0005-surface-sam.patch 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567
  1. From 956e4d21cae3e7ad4f652a7b88dcfbaa431613ed Mon Sep 17 00:00:00 2001
  2. From: Maximilian Luz <luzmaximilian@gmail.com>
  3. Date: Tue, 8 Jun 2021 00:24:47 +0200
  4. Subject: [PATCH] platform/surface: aggregator: Allow devices to be marked as
  5. hot-removed
  6. Some SSAM devices, notably the keyboard cover (keyboard and touchpad) on
  7. the Surface Pro 8, can be hot-removed. When this occurs, communication
  8. with the device may fail and time out. This timeout can unnecessarily
  9. block and slow down device removal and even cause issues when the
  10. devices are detached and re-attached quickly. Thus, communication should
  11. generally be avoided once hot-removal is detected.
  12. While we already remove a device as soon as we detect its (hot-)removal,
  13. the corresponding device driver may still attempt to communicate with
  14. the device during teardown. This is especially critical as communication
  15. failure may also extend to disabling of events, which is typically done
  16. at that stage.
  17. Add a flag to allow marking devices as hot-removed. This can then be
  18. used during client driver teardown to check if any communication
  19. attempts should be avoided.
  20. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  21. Patchset: surface-sam
  22. ---
  23. include/linux/surface_aggregator/device.h | 48 +++++++++++++++++++++--
  24. 1 file changed, 45 insertions(+), 3 deletions(-)
  25. diff --git a/include/linux/surface_aggregator/device.h b/include/linux/surface_aggregator/device.h
  26. index cc257097eb05..491aa7e9f4bc 100644
  27. --- a/include/linux/surface_aggregator/device.h
  28. +++ b/include/linux/surface_aggregator/device.h
  29. @@ -148,17 +148,30 @@ struct ssam_device_uid {
  30. #define SSAM_SDEV(cat, tid, iid, fun) \
  31. SSAM_DEVICE(SSAM_DOMAIN_SERIALHUB, SSAM_SSH_TC_##cat, tid, iid, fun)
  32. +/*
  33. + * enum ssam_device_flags - Flags for SSAM client devices.
  34. + * @SSAM_DEVICE_HOT_REMOVED_BIT:
  35. + * The device has been hot-removed. Further communication with it may time
  36. + * out and should be avoided.
  37. + */
  38. +enum ssam_device_flags {
  39. + SSAM_DEVICE_HOT_REMOVED_BIT = 0,
  40. +};
  41. +
  42. /**
  43. * struct ssam_device - SSAM client device.
  44. - * @dev: Driver model representation of the device.
  45. - * @ctrl: SSAM controller managing this device.
  46. - * @uid: UID identifying the device.
  47. + * @dev: Driver model representation of the device.
  48. + * @ctrl: SSAM controller managing this device.
  49. + * @uid: UID identifying the device.
  50. + * @flags: Device state flags, see &enum ssam_device_flags.
  51. */
  52. struct ssam_device {
  53. struct device dev;
  54. struct ssam_controller *ctrl;
  55. struct ssam_device_uid uid;
  56. +
  57. + unsigned long flags;
  58. };
  59. /**
  60. @@ -240,6 +253,35 @@ struct ssam_device *ssam_device_alloc(struct ssam_controller *ctrl,
  61. int ssam_device_add(struct ssam_device *sdev);
  62. void ssam_device_remove(struct ssam_device *sdev);
  63. +/**
  64. + * ssam_device_mark_hot_removed() - Mark the given device as hot-removed.
  65. + * @sdev: The device to mark as hot-removed.
  66. + *
  67. + * Mark the device as having been hot-removed. This signals drivers using the
  68. + * device that communication with the device should be avoided and may lead to
  69. + * timeouts.
  70. + */
  71. +static inline void ssam_device_mark_hot_removed(struct ssam_device *sdev)
  72. +{
  73. + dev_dbg(&sdev->dev, "marking device as hot-removed\n");
  74. + set_bit(SSAM_DEVICE_HOT_REMOVED_BIT, &sdev->flags);
  75. +}
  76. +
  77. +/**
  78. + * ssam_device_is_hot_removed() - Check if the given device has been
  79. + * hot-removed.
  80. + * @sdev: The device to check.
  81. + *
  82. + * Checks if the given device has been marked as hot-removed. See
  83. + * ssam_device_mark_hot_removed() for more details.
  84. + *
  85. + * Return: Returns ``true`` if the device has been marked as hot-removed.
  86. + */
  87. +static inline bool ssam_device_is_hot_removed(struct ssam_device *sdev)
  88. +{
  89. + return test_bit(SSAM_DEVICE_HOT_REMOVED_BIT, &sdev->flags);
  90. +}
  91. +
  92. /**
  93. * ssam_device_get() - Increment reference count of SSAM client device.
  94. * @sdev: The device to increment the reference count of.
  95. --
  96. 2.36.1
  97. From fc6a2d704aa4fa7adad0cdb52418bad03fdd3239 Mon Sep 17 00:00:00 2001
  98. From: Maximilian Luz <luzmaximilian@gmail.com>
  99. Date: Tue, 8 Jun 2021 00:48:22 +0200
  100. Subject: [PATCH] platform/surface: aggregator: Allow notifiers to avoid
  101. communication on unregistering
  102. When SSAM client devices have been (physically) hot-removed,
  103. communication attempts with those devices may fail and time out. This
  104. can even extend to event notifiers, due to which timeouts may occur
  105. during device removal, slowing down that process.
  106. Add a parameter to the notifier unregister function that allows skipping
  107. communication with the EC to prevent this. Furthermore, add wrappers for
  108. registering and unregistering notifiers belonging to SSAM client devices
  109. that automatically check if the device has been marked as hot-removed
  110. and communication should be avoided.
  111. Note that non-SSAM client devices can generally not be hot-removed, so
  112. also add a convenience wrapper for those, defaulting to allow
  113. communication.
  114. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  115. Patchset: surface-sam
  116. ---
  117. .../driver-api/surface_aggregator/client.rst | 6 +-
  118. .../platform/surface/aggregator/controller.c | 53 ++++++++++-----
  119. include/linux/surface_aggregator/controller.h | 24 ++++++-
  120. include/linux/surface_aggregator/device.h | 66 +++++++++++++++++++
  121. 4 files changed, 128 insertions(+), 21 deletions(-)
  122. diff --git a/Documentation/driver-api/surface_aggregator/client.rst b/Documentation/driver-api/surface_aggregator/client.rst
  123. index e519d374c378..27f95abdbe99 100644
  124. --- a/Documentation/driver-api/surface_aggregator/client.rst
  125. +++ b/Documentation/driver-api/surface_aggregator/client.rst
  126. @@ -17,6 +17,8 @@
  127. .. |SSAM_DEVICE| replace:: :c:func:`SSAM_DEVICE`
  128. .. |ssam_notifier_register| replace:: :c:func:`ssam_notifier_register`
  129. .. |ssam_notifier_unregister| replace:: :c:func:`ssam_notifier_unregister`
  130. +.. |ssam_device_notifier_register| replace:: :c:func:`ssam_device_notifier_register`
  131. +.. |ssam_device_notifier_unregister| replace:: :c:func:`ssam_device_notifier_unregister`
  132. .. |ssam_request_sync| replace:: :c:func:`ssam_request_sync`
  133. .. |ssam_event_mask| replace:: :c:type:`enum ssam_event_mask <ssam_event_mask>`
  134. @@ -312,7 +314,9 @@ Handling Events
  135. To receive events from the SAM EC, an event notifier must be registered for
  136. the desired event via |ssam_notifier_register|. The notifier must be
  137. unregistered via |ssam_notifier_unregister| once it is not required any
  138. -more.
  139. +more. For |ssam_device| type clients, the |ssam_device_notifier_register| and
  140. +|ssam_device_notifier_unregister| wrappers should be preferred as they properly
  141. +handle hot-removal of client devices.
  142. Event notifiers are registered by providing (at minimum) a callback to call
  143. in case an event has been received, the registry specifying how the event
  144. diff --git a/drivers/platform/surface/aggregator/controller.c b/drivers/platform/surface/aggregator/controller.c
  145. index b8c377b3f932..6de834b52b63 100644
  146. --- a/drivers/platform/surface/aggregator/controller.c
  147. +++ b/drivers/platform/surface/aggregator/controller.c
  148. @@ -2199,16 +2199,26 @@ static int ssam_nf_refcount_enable(struct ssam_controller *ctrl,
  149. }
  150. /**
  151. - * ssam_nf_refcount_disable_free() - Disable event for reference count entry if it is
  152. - * no longer in use and free the corresponding entry.
  153. + * ssam_nf_refcount_disable_free() - Disable event for reference count entry if
  154. + * it is no longer in use and free the corresponding entry.
  155. * @ctrl: The controller to disable the event on.
  156. * @entry: The reference count entry for the event to be disabled.
  157. * @flags: The flags used for enabling the event on the EC.
  158. + * @ec: Flag specifying if the event should actually be disabled on the EC.
  159. *
  160. - * If the reference count equals zero, i.e. the event is no longer requested by
  161. - * any client, the event will be disabled and the corresponding reference count
  162. - * entry freed. The reference count entry must not be used any more after a
  163. - * call to this function.
  164. + * If ``ec`` equals ``true`` and the reference count equals zero (i.e. the
  165. + * event is no longer requested by any client), the specified event will be
  166. + * disabled on the EC via the corresponding request.
  167. + *
  168. + * If ``ec`` equals ``false``, no request will be sent to the EC and the event
  169. + * can be considered in a detached state (i.e. no longer used but still
  170. + * enabled). Disabling an event via this method may be required for
  171. + * hot-removable devices, where event disable requests may time out after the
  172. + * device has been physically removed.
  173. + *
  174. + * In both cases, if the reference count equals zero, the corresponding
  175. + * reference count entry will be freed. The reference count entry must not be
  176. + * used any more after a call to this function.
  177. *
  178. * Also checks if the flags used for disabling the event match the flags used
  179. * for enabling the event and warns if they do not (regardless of reference
  180. @@ -2223,7 +2233,7 @@ static int ssam_nf_refcount_enable(struct ssam_controller *ctrl,
  181. * returns the status of the event-enable EC command.
  182. */
  183. static int ssam_nf_refcount_disable_free(struct ssam_controller *ctrl,
  184. - struct ssam_nf_refcount_entry *entry, u8 flags)
  185. + struct ssam_nf_refcount_entry *entry, u8 flags, bool ec)
  186. {
  187. const struct ssam_event_registry reg = entry->key.reg;
  188. const struct ssam_event_id id = entry->key.id;
  189. @@ -2232,8 +2242,9 @@ static int ssam_nf_refcount_disable_free(struct ssam_controller *ctrl,
  190. lockdep_assert_held(&nf->lock);
  191. - ssam_dbg(ctrl, "disabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n",
  192. - reg.target_category, id.target_category, id.instance, entry->refcount);
  193. + ssam_dbg(ctrl, "%s event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n",
  194. + ec ? "disabling" : "detaching", reg.target_category, id.target_category,
  195. + id.instance, entry->refcount);
  196. if (entry->flags != flags) {
  197. ssam_warn(ctrl,
  198. @@ -2242,7 +2253,7 @@ static int ssam_nf_refcount_disable_free(struct ssam_controller *ctrl,
  199. id.instance);
  200. }
  201. - if (entry->refcount == 0) {
  202. + if (ec && entry->refcount == 0) {
  203. status = ssam_ssh_event_disable(ctrl, reg, id, flags);
  204. kfree(entry);
  205. }
  206. @@ -2322,20 +2333,26 @@ int ssam_notifier_register(struct ssam_controller *ctrl, struct ssam_event_notif
  207. EXPORT_SYMBOL_GPL(ssam_notifier_register);
  208. /**
  209. - * ssam_notifier_unregister() - Unregister an event notifier.
  210. - * @ctrl: The controller the notifier has been registered on.
  211. - * @n: The event notifier to unregister.
  212. + * __ssam_notifier_unregister() - Unregister an event notifier.
  213. + * @ctrl: The controller the notifier has been registered on.
  214. + * @n: The event notifier to unregister.
  215. + * @disable: Whether to disable the corresponding event on the EC.
  216. *
  217. * Unregister an event notifier. Decrement the usage counter of the associated
  218. * SAM event if the notifier is not marked as an observer. If the usage counter
  219. - * reaches zero, the event will be disabled.
  220. + * reaches zero and ``disable`` equals ``true``, the event will be disabled.
  221. + *
  222. + * Useful for hot-removable devices, where communication may fail once the
  223. + * device has been physically removed. In that case, specifying ``disable`` as
  224. + * ``false`` avoids communication with the EC.
  225. *
  226. * Return: Returns zero on success, %-ENOENT if the given notifier block has
  227. * not been registered on the controller. If the given notifier block was the
  228. * last one associated with its specific event, returns the status of the
  229. * event-disable EC-command.
  230. */
  231. -int ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_notifier *n)
  232. +int __ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_notifier *n,
  233. + bool disable)
  234. {
  235. u16 rqid = ssh_tc_to_rqid(n->event.id.target_category);
  236. struct ssam_nf_refcount_entry *entry;
  237. @@ -2373,7 +2390,7 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_not
  238. goto remove;
  239. }
  240. - status = ssam_nf_refcount_disable_free(ctrl, entry, n->event.flags);
  241. + status = ssam_nf_refcount_disable_free(ctrl, entry, n->event.flags, disable);
  242. }
  243. remove:
  244. @@ -2383,7 +2400,7 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_not
  245. return status;
  246. }
  247. -EXPORT_SYMBOL_GPL(ssam_notifier_unregister);
  248. +EXPORT_SYMBOL_GPL(__ssam_notifier_unregister);
  249. /**
  250. * ssam_controller_event_enable() - Enable the specified event.
  251. @@ -2477,7 +2494,7 @@ int ssam_controller_event_disable(struct ssam_controller *ctrl,
  252. return -ENOENT;
  253. }
  254. - status = ssam_nf_refcount_disable_free(ctrl, entry, flags);
  255. + status = ssam_nf_refcount_disable_free(ctrl, entry, flags, true);
  256. mutex_unlock(&nf->lock);
  257. return status;
  258. diff --git a/include/linux/surface_aggregator/controller.h b/include/linux/surface_aggregator/controller.h
  259. index 74bfdffaf7b0..50a2b4926c06 100644
  260. --- a/include/linux/surface_aggregator/controller.h
  261. +++ b/include/linux/surface_aggregator/controller.h
  262. @@ -835,8 +835,28 @@ struct ssam_event_notifier {
  263. int ssam_notifier_register(struct ssam_controller *ctrl,
  264. struct ssam_event_notifier *n);
  265. -int ssam_notifier_unregister(struct ssam_controller *ctrl,
  266. - struct ssam_event_notifier *n);
  267. +int __ssam_notifier_unregister(struct ssam_controller *ctrl,
  268. + struct ssam_event_notifier *n, bool disable);
  269. +
  270. +/**
  271. + * ssam_notifier_unregister() - Unregister an event notifier.
  272. + * @ctrl: The controller the notifier has been registered on.
  273. + * @n: The event notifier to unregister.
  274. + *
  275. + * Unregister an event notifier. Decrement the usage counter of the associated
  276. + * SAM event if the notifier is not marked as an observer. If the usage counter
  277. + * reaches zero, the event will be disabled.
  278. + *
  279. + * Return: Returns zero on success, %-ENOENT if the given notifier block has
  280. + * not been registered on the controller. If the given notifier block was the
  281. + * last one associated with its specific event, returns the status of the
  282. + * event-disable EC-command.
  283. + */
  284. +static inline int ssam_notifier_unregister(struct ssam_controller *ctrl,
  285. + struct ssam_event_notifier *n)
  286. +{
  287. + return __ssam_notifier_unregister(ctrl, n, true);
  288. +}
  289. int ssam_controller_event_enable(struct ssam_controller *ctrl,
  290. struct ssam_event_registry reg,
  291. diff --git a/include/linux/surface_aggregator/device.h b/include/linux/surface_aggregator/device.h
  292. index 491aa7e9f4bc..ad245c6b00d0 100644
  293. --- a/include/linux/surface_aggregator/device.h
  294. +++ b/include/linux/surface_aggregator/device.h
  295. @@ -472,4 +472,70 @@ static inline void ssam_remove_clients(struct device *dev) {}
  296. sdev->uid.instance, ret); \
  297. }
  298. +
  299. +/* -- Helpers for client-device notifiers. ---------------------------------- */
  300. +
  301. +/**
  302. + * ssam_device_notifier_register() - Register an event notifier for the
  303. + * specified client device.
  304. + * @sdev: The device the notifier should be registered on.
  305. + * @n: The event notifier to register.
  306. + *
  307. + * Register an event notifier. Increment the usage counter of the associated
  308. + * SAM event if the notifier is not marked as an observer. If the event is not
  309. + * marked as an observer and is currently not enabled, it will be enabled
  310. + * during this call. If the notifier is marked as an observer, no attempt will
  311. + * be made at enabling any event and no reference count will be modified.
  312. + *
  313. + * Notifiers marked as observers do not need to be associated with one specific
  314. + * event, i.e. as long as no event matching is performed, only the event target
  315. + * category needs to be set.
  316. + *
  317. + * Return: Returns zero on success, %-ENOSPC if there have already been
  318. + * %INT_MAX notifiers for the event ID/type associated with the notifier block
  319. + * registered, %-ENOMEM if the corresponding event entry could not be
  320. + * allocated, %-ENODEV if the device is marked as hot-removed. If this is the
  321. + * first time that a notifier block is registered for the specific associated
  322. + * event, returns the status of the event-enable EC-command.
  323. + */
  324. +static inline int ssam_device_notifier_register(struct ssam_device *sdev,
  325. + struct ssam_event_notifier *n)
  326. +{
  327. + /*
  328. + * Note that this check does not provide any guarantees whatsoever as
  329. + * hot-removal could happen at any point and we can't protect against
  330. + * it. Nevertheless, if we can detect hot-removal, bail early to avoid
  331. + * communication timeouts.
  332. + */
  333. + if (ssam_device_is_hot_removed(sdev))
  334. + return -ENODEV;
  335. +
  336. + return ssam_notifier_register(sdev->ctrl, n);
  337. +}
  338. +
  339. +/**
  340. + * ssam_device_notifier_unregister() - Unregister an event notifier for the
  341. + * specified client device.
  342. + * @sdev: The device the notifier has been registered on.
  343. + * @n: The event notifier to unregister.
  344. + *
  345. + * Unregister an event notifier. Decrement the usage counter of the associated
  346. + * SAM event if the notifier is not marked as an observer. If the usage counter
  347. + * reaches zero, the event will be disabled.
  348. + *
  349. + * In case the device has been marked as hot-removed, the event will not be
  350. + * disabled on the EC, as in those cases any attempt at doing so may time out.
  351. + *
  352. + * Return: Returns zero on success, %-ENOENT if the given notifier block has
  353. + * not been registered on the controller. If the given notifier block was the
  354. + * last one associated with its specific event, returns the status of the
  355. + * event-disable EC-command.
  356. + */
  357. +static inline int ssam_device_notifier_unregister(struct ssam_device *sdev,
  358. + struct ssam_event_notifier *n)
  359. +{
  360. + return __ssam_notifier_unregister(sdev->ctrl, n,
  361. + !ssam_device_is_hot_removed(sdev));
  362. +}
  363. +
  364. #endif /* _LINUX_SURFACE_AGGREGATOR_DEVICE_H */
  365. --
  366. 2.36.1
  367. From a20d4cf113fb4d38e431488007489384b2b2f807 Mon Sep 17 00:00:00 2001
  368. From: Maximilian Luz <luzmaximilian@gmail.com>
  369. Date: Tue, 8 Jun 2021 01:20:49 +0200
  370. Subject: [PATCH] platform/surface: aggregator_registry: Use client device
  371. wrappers for notifier registration
  372. Use newly introduced client device wrapper functions for notifier
  373. registration and unregistration.
  374. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  375. Patchset: surface-sam
  376. ---
  377. drivers/platform/surface/surface_aggregator_registry.c | 6 +++---
  378. 1 file changed, 3 insertions(+), 3 deletions(-)
  379. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  380. index ce2bd88feeaa..9f630e890ff7 100644
  381. --- a/drivers/platform/surface/surface_aggregator_registry.c
  382. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  383. @@ -468,7 +468,7 @@ static int ssam_base_hub_probe(struct ssam_device *sdev)
  384. ssam_device_set_drvdata(sdev, hub);
  385. - status = ssam_notifier_register(sdev->ctrl, &hub->notif);
  386. + status = ssam_device_notifier_register(sdev, &hub->notif);
  387. if (status)
  388. return status;
  389. @@ -480,7 +480,7 @@ static int ssam_base_hub_probe(struct ssam_device *sdev)
  390. return 0;
  391. err:
  392. - ssam_notifier_unregister(sdev->ctrl, &hub->notif);
  393. + ssam_device_notifier_unregister(sdev, &hub->notif);
  394. cancel_delayed_work_sync(&hub->update_work);
  395. ssam_remove_clients(&sdev->dev);
  396. return status;
  397. @@ -492,7 +492,7 @@ static void ssam_base_hub_remove(struct ssam_device *sdev)
  398. sysfs_remove_group(&sdev->dev.kobj, &ssam_base_hub_group);
  399. - ssam_notifier_unregister(sdev->ctrl, &hub->notif);
  400. + ssam_device_notifier_unregister(sdev, &hub->notif);
  401. cancel_delayed_work_sync(&hub->update_work);
  402. ssam_remove_clients(&sdev->dev);
  403. }
  404. --
  405. 2.36.1
  406. From 6863a5a91ec549ba5293c9b4e796869ebb22b34a Mon Sep 17 00:00:00 2001
  407. From: Maximilian Luz <luzmaximilian@gmail.com>
  408. Date: Thu, 28 Oct 2021 03:37:06 +0200
  409. Subject: [PATCH] power/supply: surface_charger: Use client device wrappers for
  410. notifier registration
  411. Use newly introduced client device wrapper functions for notifier
  412. registration and unregistration.
  413. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  414. Patchset: surface-sam
  415. ---
  416. drivers/power/supply/surface_charger.c | 4 ++--
  417. 1 file changed, 2 insertions(+), 2 deletions(-)
  418. diff --git a/drivers/power/supply/surface_charger.c b/drivers/power/supply/surface_charger.c
  419. index a060c36c7766..59182d55742d 100644
  420. --- a/drivers/power/supply/surface_charger.c
  421. +++ b/drivers/power/supply/surface_charger.c
  422. @@ -216,7 +216,7 @@ static int spwr_ac_register(struct spwr_ac_device *ac)
  423. if (IS_ERR(ac->psy))
  424. return PTR_ERR(ac->psy);
  425. - return ssam_notifier_register(ac->sdev->ctrl, &ac->notif);
  426. + return ssam_device_notifier_register(ac->sdev, &ac->notif);
  427. }
  428. @@ -251,7 +251,7 @@ static void surface_ac_remove(struct ssam_device *sdev)
  429. {
  430. struct spwr_ac_device *ac = ssam_device_get_drvdata(sdev);
  431. - ssam_notifier_unregister(sdev->ctrl, &ac->notif);
  432. + ssam_device_notifier_unregister(sdev, &ac->notif);
  433. }
  434. static const struct spwr_psy_properties spwr_psy_props_adp1 = {
  435. --
  436. 2.36.1
  437. From d0917349c7cd43f2067d048bbfd9cee5726e1883 Mon Sep 17 00:00:00 2001
  438. From: Maximilian Luz <luzmaximilian@gmail.com>
  439. Date: Thu, 28 Oct 2021 03:38:09 +0200
  440. Subject: [PATCH] power/supply: surface_battery: Use client device wrappers for
  441. notifier registration
  442. Use newly introduced client device wrapper functions for notifier
  443. registration and unregistration.
  444. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  445. Patchset: surface-sam
  446. ---
  447. drivers/power/supply/surface_battery.c | 4 ++--
  448. 1 file changed, 2 insertions(+), 2 deletions(-)
  449. diff --git a/drivers/power/supply/surface_battery.c b/drivers/power/supply/surface_battery.c
  450. index 5ec2e6bb2465..540707882bb0 100644
  451. --- a/drivers/power/supply/surface_battery.c
  452. +++ b/drivers/power/supply/surface_battery.c
  453. @@ -802,7 +802,7 @@ static int spwr_battery_register(struct spwr_battery_device *bat)
  454. if (IS_ERR(bat->psy))
  455. return PTR_ERR(bat->psy);
  456. - return ssam_notifier_register(bat->sdev->ctrl, &bat->notif);
  457. + return ssam_device_notifier_register(bat->sdev, &bat->notif);
  458. }
  459. @@ -837,7 +837,7 @@ static void surface_battery_remove(struct ssam_device *sdev)
  460. {
  461. struct spwr_battery_device *bat = ssam_device_get_drvdata(sdev);
  462. - ssam_notifier_unregister(sdev->ctrl, &bat->notif);
  463. + ssam_device_notifier_unregister(sdev, &bat->notif);
  464. cancel_delayed_work_sync(&bat->update_work);
  465. }
  466. --
  467. 2.36.1
  468. From 6730bf6e58208c3097a89e71c62b44f9f8b61408 Mon Sep 17 00:00:00 2001
  469. From: Maximilian Luz <luzmaximilian@gmail.com>
  470. Date: Tue, 8 Jun 2021 01:33:02 +0200
  471. Subject: [PATCH] HID: surface-hid: Add support for hot-removal
  472. Add support for hot-removal of SSAM HID client devices.
  473. Once a device has been hot-removed, further communication with it should
  474. be avoided as it may fail and time out. While the device will be removed
  475. as soon as we detect hot-removal, communication may still occur during
  476. teardown, especially when unregistering notifiers.
  477. While hot-removal is a surprise event that can happen at any time, try
  478. to avoid communication as much as possible once it has been detected to
  479. prevent timeouts that can slow down device removal and cause issues,
  480. e.g. when quickly re-attaching the device.
  481. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  482. Patchset: surface-sam
  483. ---
  484. drivers/hid/surface-hid/surface_hid_core.c | 38 +++++++++++++++++++++-
  485. 1 file changed, 37 insertions(+), 1 deletion(-)
  486. diff --git a/drivers/hid/surface-hid/surface_hid_core.c b/drivers/hid/surface-hid/surface_hid_core.c
  487. index e46330b2e561..87637f813de2 100644
  488. --- a/drivers/hid/surface-hid/surface_hid_core.c
  489. +++ b/drivers/hid/surface-hid/surface_hid_core.c
  490. @@ -19,12 +19,30 @@
  491. #include "surface_hid_core.h"
  492. +/* -- Utility functions. ---------------------------------------------------- */
  493. +
  494. +static bool surface_hid_is_hot_removed(struct surface_hid_device *shid)
  495. +{
  496. + /*
  497. + * Non-ssam client devices, i.e. platform client devices, cannot be
  498. + * hot-removed.
  499. + */
  500. + if (!is_ssam_device(shid->dev))
  501. + return false;
  502. +
  503. + return ssam_device_is_hot_removed(to_ssam_device(shid->dev));
  504. +}
  505. +
  506. +
  507. /* -- Device descriptor access. --------------------------------------------- */
  508. static int surface_hid_load_hid_descriptor(struct surface_hid_device *shid)
  509. {
  510. int status;
  511. + if (surface_hid_is_hot_removed(shid))
  512. + return -ENODEV;
  513. +
  514. status = shid->ops.get_descriptor(shid, SURFACE_HID_DESC_HID,
  515. (u8 *)&shid->hid_desc, sizeof(shid->hid_desc));
  516. if (status)
  517. @@ -61,6 +79,9 @@ static int surface_hid_load_device_attributes(struct surface_hid_device *shid)
  518. {
  519. int status;
  520. + if (surface_hid_is_hot_removed(shid))
  521. + return -ENODEV;
  522. +
  523. status = shid->ops.get_descriptor(shid, SURFACE_HID_DESC_ATTRS,
  524. (u8 *)&shid->attrs, sizeof(shid->attrs));
  525. if (status)
  526. @@ -88,9 +109,18 @@ static int surface_hid_start(struct hid_device *hid)
  527. static void surface_hid_stop(struct hid_device *hid)
  528. {
  529. struct surface_hid_device *shid = hid->driver_data;
  530. + bool hot_removed;
  531. +
  532. + /*
  533. + * Communication may fail for devices that have been hot-removed. This
  534. + * also includes unregistration of HID events, so we need to check this
  535. + * here. Only if the device has not been marked as hot-removed, we can
  536. + * safely disable events.
  537. + */
  538. + hot_removed = surface_hid_is_hot_removed(shid);
  539. /* Note: This call will log errors for us, so ignore them here. */
  540. - ssam_notifier_unregister(shid->ctrl, &shid->notif);
  541. + __ssam_notifier_unregister(shid->ctrl, &shid->notif, !hot_removed);
  542. }
  543. static int surface_hid_open(struct hid_device *hid)
  544. @@ -109,6 +139,9 @@ static int surface_hid_parse(struct hid_device *hid)
  545. u8 *buf;
  546. int status;
  547. + if (surface_hid_is_hot_removed(shid))
  548. + return -ENODEV;
  549. +
  550. buf = kzalloc(len, GFP_KERNEL);
  551. if (!buf)
  552. return -ENOMEM;
  553. @@ -126,6 +159,9 @@ static int surface_hid_raw_request(struct hid_device *hid, unsigned char reportn
  554. {
  555. struct surface_hid_device *shid = hid->driver_data;
  556. + if (surface_hid_is_hot_removed(shid))
  557. + return -ENODEV;
  558. +
  559. if (rtype == HID_OUTPUT_REPORT && reqtype == HID_REQ_SET_REPORT)
  560. return shid->ops.output_report(shid, reportnum, buf, len);
  561. --
  562. 2.36.1
  563. From 987fd2ce1f77db64bb6bfc4372f53569ff9279e6 Mon Sep 17 00:00:00 2001
  564. From: Maximilian Luz <luzmaximilian@gmail.com>
  565. Date: Sun, 31 Oct 2021 12:34:08 +0100
  566. Subject: [PATCH] platform/surface: aggregator: Add comment for KIP subsystem
  567. category
  568. The KIP subsystem (full name unknown, abbreviation has been obtained
  569. through reverse engineering) handles detachable peripherals such as the
  570. keyboard cover on the Surface Pro X and Surface Pro 8.
  571. It is currently not entirely clear what this subsystem entails, but at
  572. the very least it provides event notifications for when the keyboard
  573. cover on the Surface Pro X and Surface Pro 8 have been detached or
  574. re-attached, as well as the state that the keyboard cover is currently
  575. in (e.g. folded-back, folded laptop-like, closed, etc.).
  576. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  577. Patchset: surface-sam
  578. ---
  579. include/linux/surface_aggregator/serial_hub.h | 2 +-
  580. 1 file changed, 1 insertion(+), 1 deletion(-)
  581. diff --git a/include/linux/surface_aggregator/serial_hub.h b/include/linux/surface_aggregator/serial_hub.h
  582. index c3de43edcffa..26b95ec12733 100644
  583. --- a/include/linux/surface_aggregator/serial_hub.h
  584. +++ b/include/linux/surface_aggregator/serial_hub.h
  585. @@ -306,7 +306,7 @@ enum ssam_ssh_tc {
  586. SSAM_SSH_TC_LPC = 0x0b,
  587. SSAM_SSH_TC_TCL = 0x0c,
  588. SSAM_SSH_TC_SFL = 0x0d,
  589. - SSAM_SSH_TC_KIP = 0x0e,
  590. + SSAM_SSH_TC_KIP = 0x0e, /* Manages detachable peripherals (Pro X/8 keyboard cover) */
  591. SSAM_SSH_TC_EXT = 0x0f,
  592. SSAM_SSH_TC_BLD = 0x10,
  593. SSAM_SSH_TC_BAS = 0x11, /* Detachment system (Surface Book 2/3). */
  594. --
  595. 2.36.1
  596. From 638f1160c139d4b8847eff3e18db47c0b84f6b0d Mon Sep 17 00:00:00 2001
  597. From: Maximilian Luz <luzmaximilian@gmail.com>
  598. Date: Fri, 29 Apr 2022 22:42:32 +0200
  599. Subject: [PATCH] platform/surface: aggregator_registry: Generify subsystem hub
  600. functionality
  601. The Surface System Aggregator Module (SSAM) has multiple subsystems that
  602. can manage detachable devices. At the moment, we only support the "base"
  603. (BAS/0x11) subsystem, which is used on the Surface Book 3 to manage
  604. devices (including keyboard, touchpad, and secondary battery) connected
  605. to the base of the device.
  606. The Surface Pro 8 has a new type-cover with keyboard and touchpad, which
  607. is managed via the KIP/0x0e subsystem. The general procedure is the
  608. same, but with slightly different events and setup. To make
  609. implementation of the KIP hub easier and prevent duplication, generify
  610. the parts of the base hub that we can use for the KIP hub (or any
  611. potential future subsystem hubs).
  612. This also switches over to use the newly introduced "hot-remove"
  613. functionality, which should prevent communication issues when devices
  614. have been detached.
  615. Lastly, also drop the undocumented and unused sysfs "state" attribute of
  616. the base hub. It has at best been useful for debugging.
  617. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  618. Patchset: surface-sam
  619. ---
  620. .../surface/surface_aggregator_registry.c | 269 ++++++++++--------
  621. 1 file changed, 153 insertions(+), 116 deletions(-)
  622. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  623. index 9f630e890ff7..09cbeee2428b 100644
  624. --- a/drivers/platform/surface/surface_aggregator_registry.c
  625. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  626. @@ -308,30 +308,159 @@ static int ssam_hub_register_clients(struct device *parent, struct ssam_controll
  627. }
  628. -/* -- SSAM base-hub driver. ------------------------------------------------- */
  629. +/* -- SSAM generic subsystem hub driver framework. -------------------------- */
  630. -/*
  631. - * Some devices (especially battery) may need a bit of time to be fully usable
  632. - * after being (re-)connected. This delay has been determined via
  633. - * experimentation.
  634. - */
  635. -#define SSAM_BASE_UPDATE_CONNECT_DELAY msecs_to_jiffies(2500)
  636. +enum ssam_hub_state {
  637. + SSAM_HUB_UNINITIALIZED, /* Only set during initialization. */
  638. + SSAM_HUB_CONNECTED,
  639. + SSAM_HUB_DISCONNECTED,
  640. +};
  641. -enum ssam_base_hub_state {
  642. - SSAM_BASE_HUB_UNINITIALIZED,
  643. - SSAM_BASE_HUB_CONNECTED,
  644. - SSAM_BASE_HUB_DISCONNECTED,
  645. +enum ssam_hub_flags {
  646. + SSAM_HUB_HOT_REMOVED,
  647. };
  648. -struct ssam_base_hub {
  649. +struct ssam_hub {
  650. struct ssam_device *sdev;
  651. - enum ssam_base_hub_state state;
  652. + enum ssam_hub_state state;
  653. + unsigned long flags;
  654. +
  655. struct delayed_work update_work;
  656. + unsigned long connect_delay;
  657. struct ssam_event_notifier notif;
  658. +
  659. + int (*get_state)(struct ssam_hub *hub, enum ssam_hub_state *state);
  660. };
  661. +static void ssam_hub_update_workfn(struct work_struct *work)
  662. +{
  663. + struct ssam_hub *hub = container_of(work, struct ssam_hub, update_work.work);
  664. + struct fwnode_handle *node = dev_fwnode(&hub->sdev->dev);
  665. + enum ssam_hub_state state;
  666. + int status = 0;
  667. +
  668. + status = hub->get_state(hub, &state);
  669. + if (status)
  670. + return;
  671. +
  672. + /*
  673. + * There is a small possibility that hub devices were hot-removed and
  674. + * re-added before we were able to remove them here. In that case, both
  675. + * the state returned by get_state() and the state of the hub will
  676. + * equal SSAM_HUB_CONNECTED and we would bail early below, which would
  677. + * leave child devices without proper (re-)initialization and the
  678. + * hot-remove flag set.
  679. + *
  680. + * Therefore, we check whether devices have been hot-removed via an
  681. + * additional flag on the hub and, in this case, override the returned
  682. + * hub state. In case of a missed disconnect (i.e. get_state returned
  683. + * "connected"), we further need to re-schedule this work (with the
  684. + * appropriate delay) as the actual connect work submission might have
  685. + * been merged with this one.
  686. + *
  687. + * This then leads to one of two cases: Either we submit an unnecessary
  688. + * work item (which will get ignored via either the queue or the state
  689. + * checks) or, in the unlikely case that the work is actually required,
  690. + * double the normal connect delay.
  691. + */
  692. + if (test_and_clear_bit(SSAM_HUB_HOT_REMOVED, &hub->flags)) {
  693. + if (state == SSAM_HUB_CONNECTED)
  694. + schedule_delayed_work(&hub->update_work, hub->connect_delay);
  695. +
  696. + state = SSAM_HUB_DISCONNECTED;
  697. + }
  698. +
  699. + if (hub->state == state)
  700. + return;
  701. + hub->state = state;
  702. +
  703. + if (hub->state == SSAM_HUB_CONNECTED)
  704. + status = ssam_hub_register_clients(&hub->sdev->dev, hub->sdev->ctrl, node);
  705. + else
  706. + ssam_remove_clients(&hub->sdev->dev);
  707. +
  708. + if (status)
  709. + dev_err(&hub->sdev->dev, "failed to update hub child devices: %d\n", status);
  710. +}
  711. +
  712. +static int ssam_hub_mark_hot_removed(struct device *dev, void *_data)
  713. +{
  714. + struct ssam_device *sdev = to_ssam_device(dev);
  715. +
  716. + if (is_ssam_device(dev))
  717. + ssam_device_mark_hot_removed(sdev);
  718. +
  719. + return 0;
  720. +}
  721. +
  722. +static void ssam_hub_update(struct ssam_hub *hub, bool connected)
  723. +{
  724. + unsigned long delay;
  725. +
  726. + /* Mark devices as hot-removed before we remove any. */
  727. + if (!connected) {
  728. + set_bit(SSAM_HUB_HOT_REMOVED, &hub->flags);
  729. + device_for_each_child_reverse(&hub->sdev->dev, NULL, ssam_hub_mark_hot_removed);
  730. + }
  731. +
  732. + /*
  733. + * Delay update when the base/keyboard cover is being connected to give
  734. + * devices/EC some time to set up.
  735. + */
  736. + delay = connected ? hub->connect_delay : 0;
  737. +
  738. + schedule_delayed_work(&hub->update_work, delay);
  739. +}
  740. +
  741. +static int __maybe_unused ssam_hub_resume(struct device *dev)
  742. +{
  743. + struct ssam_hub *hub = dev_get_drvdata(dev);
  744. +
  745. + schedule_delayed_work(&hub->update_work, 0);
  746. + return 0;
  747. +}
  748. +static SIMPLE_DEV_PM_OPS(ssam_hub_pm_ops, NULL, ssam_hub_resume);
  749. +
  750. +static int ssam_hub_setup(struct ssam_device *sdev, struct ssam_hub *hub)
  751. +{
  752. + int status;
  753. +
  754. + hub->sdev = sdev;
  755. + hub->state = SSAM_HUB_UNINITIALIZED;
  756. +
  757. + INIT_DELAYED_WORK(&hub->update_work, ssam_hub_update_workfn);
  758. +
  759. + ssam_device_set_drvdata(sdev, hub);
  760. +
  761. + status = ssam_device_notifier_register(sdev, &hub->notif);
  762. + if (status)
  763. + return status;
  764. +
  765. + schedule_delayed_work(&hub->update_work, 0);
  766. + return 0;
  767. +}
  768. +
  769. +static void ssam_hub_remove(struct ssam_device *sdev)
  770. +{
  771. + struct ssam_hub *hub = ssam_device_get_drvdata(sdev);
  772. +
  773. + ssam_device_notifier_unregister(sdev, &hub->notif);
  774. + cancel_delayed_work_sync(&hub->update_work);
  775. + ssam_remove_clients(&sdev->dev);
  776. +}
  777. +
  778. +
  779. +/* -- SSAM base-hub driver. ------------------------------------------------- */
  780. +
  781. +/*
  782. + * Some devices (especially battery) may need a bit of time to be fully usable
  783. + * after being (re-)connected. This delay has been determined via
  784. + * experimentation.
  785. + */
  786. +#define SSAM_BASE_UPDATE_CONNECT_DELAY msecs_to_jiffies(2500)
  787. +
  788. SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_query_opmode, u8, {
  789. .target_category = SSAM_SSH_TC_BAS,
  790. .target_id = 0x01,
  791. @@ -342,7 +471,7 @@ SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_query_opmode, u8, {
  792. #define SSAM_BAS_OPMODE_TABLET 0x00
  793. #define SSAM_EVENT_BAS_CID_CONNECTION 0x0c
  794. -static int ssam_base_hub_query_state(struct ssam_base_hub *hub, enum ssam_base_hub_state *state)
  795. +static int ssam_base_hub_query_state(struct ssam_hub *hub, enum ssam_hub_state *state)
  796. {
  797. u8 opmode;
  798. int status;
  799. @@ -354,62 +483,16 @@ static int ssam_base_hub_query_state(struct ssam_base_hub *hub, enum ssam_base_h
  800. }
  801. if (opmode != SSAM_BAS_OPMODE_TABLET)
  802. - *state = SSAM_BASE_HUB_CONNECTED;
  803. + *state = SSAM_HUB_CONNECTED;
  804. else
  805. - *state = SSAM_BASE_HUB_DISCONNECTED;
  806. + *state = SSAM_HUB_DISCONNECTED;
  807. return 0;
  808. }
  809. -static ssize_t ssam_base_hub_state_show(struct device *dev, struct device_attribute *attr,
  810. - char *buf)
  811. -{
  812. - struct ssam_base_hub *hub = dev_get_drvdata(dev);
  813. - bool connected = hub->state == SSAM_BASE_HUB_CONNECTED;
  814. -
  815. - return sysfs_emit(buf, "%d\n", connected);
  816. -}
  817. -
  818. -static struct device_attribute ssam_base_hub_attr_state =
  819. - __ATTR(state, 0444, ssam_base_hub_state_show, NULL);
  820. -
  821. -static struct attribute *ssam_base_hub_attrs[] = {
  822. - &ssam_base_hub_attr_state.attr,
  823. - NULL,
  824. -};
  825. -
  826. -static const struct attribute_group ssam_base_hub_group = {
  827. - .attrs = ssam_base_hub_attrs,
  828. -};
  829. -
  830. -static void ssam_base_hub_update_workfn(struct work_struct *work)
  831. -{
  832. - struct ssam_base_hub *hub = container_of(work, struct ssam_base_hub, update_work.work);
  833. - struct fwnode_handle *node = dev_fwnode(&hub->sdev->dev);
  834. - enum ssam_base_hub_state state;
  835. - int status = 0;
  836. -
  837. - status = ssam_base_hub_query_state(hub, &state);
  838. - if (status)
  839. - return;
  840. -
  841. - if (hub->state == state)
  842. - return;
  843. - hub->state = state;
  844. -
  845. - if (hub->state == SSAM_BASE_HUB_CONNECTED)
  846. - status = ssam_hub_register_clients(&hub->sdev->dev, hub->sdev->ctrl, node);
  847. - else
  848. - ssam_remove_clients(&hub->sdev->dev);
  849. -
  850. - if (status)
  851. - dev_err(&hub->sdev->dev, "failed to update base-hub devices: %d\n", status);
  852. -}
  853. -
  854. static u32 ssam_base_hub_notif(struct ssam_event_notifier *nf, const struct ssam_event *event)
  855. {
  856. - struct ssam_base_hub *hub = container_of(nf, struct ssam_base_hub, notif);
  857. - unsigned long delay;
  858. + struct ssam_hub *hub = container_of(nf, struct ssam_hub, notif);
  859. if (event->command_id != SSAM_EVENT_BAS_CID_CONNECTION)
  860. return 0;
  861. @@ -419,13 +502,7 @@ static u32 ssam_base_hub_notif(struct ssam_event_notifier *nf, const struct ssam
  862. return 0;
  863. }
  864. - /*
  865. - * Delay update when the base is being connected to give devices/EC
  866. - * some time to set up.
  867. - */
  868. - delay = event->data[0] ? SSAM_BASE_UPDATE_CONNECT_DELAY : 0;
  869. -
  870. - schedule_delayed_work(&hub->update_work, delay);
  871. + ssam_hub_update(hub, event->data[0]);
  872. /*
  873. * Do not return SSAM_NOTIF_HANDLED: The event should be picked up and
  874. @@ -435,27 +512,14 @@ static u32 ssam_base_hub_notif(struct ssam_event_notifier *nf, const struct ssam
  875. return 0;
  876. }
  877. -static int __maybe_unused ssam_base_hub_resume(struct device *dev)
  878. -{
  879. - struct ssam_base_hub *hub = dev_get_drvdata(dev);
  880. -
  881. - schedule_delayed_work(&hub->update_work, 0);
  882. - return 0;
  883. -}
  884. -static SIMPLE_DEV_PM_OPS(ssam_base_hub_pm_ops, NULL, ssam_base_hub_resume);
  885. -
  886. static int ssam_base_hub_probe(struct ssam_device *sdev)
  887. {
  888. - struct ssam_base_hub *hub;
  889. - int status;
  890. + struct ssam_hub *hub;
  891. hub = devm_kzalloc(&sdev->dev, sizeof(*hub), GFP_KERNEL);
  892. if (!hub)
  893. return -ENOMEM;
  894. - hub->sdev = sdev;
  895. - hub->state = SSAM_BASE_HUB_UNINITIALIZED;
  896. -
  897. hub->notif.base.priority = INT_MAX; /* This notifier should run first. */
  898. hub->notif.base.fn = ssam_base_hub_notif;
  899. hub->notif.event.reg = SSAM_EVENT_REGISTRY_SAM;
  900. @@ -464,37 +528,10 @@ static int ssam_base_hub_probe(struct ssam_device *sdev)
  901. hub->notif.event.mask = SSAM_EVENT_MASK_NONE;
  902. hub->notif.event.flags = SSAM_EVENT_SEQUENCED;
  903. - INIT_DELAYED_WORK(&hub->update_work, ssam_base_hub_update_workfn);
  904. -
  905. - ssam_device_set_drvdata(sdev, hub);
  906. -
  907. - status = ssam_device_notifier_register(sdev, &hub->notif);
  908. - if (status)
  909. - return status;
  910. -
  911. - status = sysfs_create_group(&sdev->dev.kobj, &ssam_base_hub_group);
  912. - if (status)
  913. - goto err;
  914. -
  915. - schedule_delayed_work(&hub->update_work, 0);
  916. - return 0;
  917. + hub->connect_delay = SSAM_BASE_UPDATE_CONNECT_DELAY;
  918. + hub->get_state = ssam_base_hub_query_state;
  919. -err:
  920. - ssam_device_notifier_unregister(sdev, &hub->notif);
  921. - cancel_delayed_work_sync(&hub->update_work);
  922. - ssam_remove_clients(&sdev->dev);
  923. - return status;
  924. -}
  925. -
  926. -static void ssam_base_hub_remove(struct ssam_device *sdev)
  927. -{
  928. - struct ssam_base_hub *hub = ssam_device_get_drvdata(sdev);
  929. -
  930. - sysfs_remove_group(&sdev->dev.kobj, &ssam_base_hub_group);
  931. -
  932. - ssam_device_notifier_unregister(sdev, &hub->notif);
  933. - cancel_delayed_work_sync(&hub->update_work);
  934. - ssam_remove_clients(&sdev->dev);
  935. + return ssam_hub_setup(sdev, hub);
  936. }
  937. static const struct ssam_device_id ssam_base_hub_match[] = {
  938. @@ -504,12 +541,12 @@ static const struct ssam_device_id ssam_base_hub_match[] = {
  939. static struct ssam_device_driver ssam_base_hub_driver = {
  940. .probe = ssam_base_hub_probe,
  941. - .remove = ssam_base_hub_remove,
  942. + .remove = ssam_hub_remove,
  943. .match_table = ssam_base_hub_match,
  944. .driver = {
  945. .name = "surface_aggregator_base_hub",
  946. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  947. - .pm = &ssam_base_hub_pm_ops,
  948. + .pm = &ssam_hub_pm_ops,
  949. },
  950. };
  951. --
  952. 2.36.1
  953. From 1a1a35dd23f7723192cdd8a1847453990f81031b Mon Sep 17 00:00:00 2001
  954. From: Maximilian Luz <luzmaximilian@gmail.com>
  955. Date: Fri, 29 Apr 2022 23:02:06 +0200
  956. Subject: [PATCH] platform/surface: aggregator_registry: Add KIP device hub
  957. Add a Surface System Aggregator Module (SSAM) client device hub for
  958. hot-removable devices managed via the KIP subsystem.
  959. The KIP subsystem (full name unknown, abbreviation has been obtained
  960. through reverse engineering) is a subsystem that manages hot-removable
  961. SSAM client devices. Specifically, it manages HID input devices
  962. contained in the detachable keyboard cover of the Surface Pro 8 and
  963. Surface Pro X.
  964. The KIP subsystem handles a single group of devices (e.g. all devices
  965. contained in the keyboard cover) and cannot handle devices individually.
  966. Thus we model it as a client device hub, which (hot-)removes all devices
  967. contained under it once removal of the hub (e.g. keyboard cover) has
  968. been detected and (re-)adds all devices once the physical hub device has
  969. been (re-)attached. To do this, use the previously generified SSAM
  970. subsystem hub framework.
  971. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  972. Patchset: surface-sam
  973. ---
  974. .../surface/surface_aggregator_registry.c | 103 +++++++++++++++++-
  975. 1 file changed, 101 insertions(+), 2 deletions(-)
  976. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  977. index 09cbeee2428b..1e60435c7cce 100644
  978. --- a/drivers/platform/surface/surface_aggregator_registry.c
  979. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  980. @@ -551,6 +551,93 @@ static struct ssam_device_driver ssam_base_hub_driver = {
  981. };
  982. +/* -- SSAM KIP-subsystem hub driver. ---------------------------------------- */
  983. +
  984. +/*
  985. + * Some devices may need a bit of time to be fully usable after being
  986. + * (re-)connected. This delay has been determined via experimentation.
  987. + */
  988. +#define SSAM_KIP_UPDATE_CONNECT_DELAY msecs_to_jiffies(250)
  989. +
  990. +#define SSAM_EVENT_KIP_CID_CONNECTION 0x2c
  991. +
  992. +SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_get_connection_state, u8, {
  993. + .target_category = SSAM_SSH_TC_KIP,
  994. + .target_id = 0x01,
  995. + .command_id = 0x2c,
  996. + .instance_id = 0x00,
  997. +});
  998. +
  999. +static int ssam_kip_get_connection_state(struct ssam_hub *hub, enum ssam_hub_state *state)
  1000. +{
  1001. + int status;
  1002. + u8 connected;
  1003. +
  1004. + status = ssam_retry(__ssam_kip_get_connection_state, hub->sdev->ctrl, &connected);
  1005. + if (status < 0) {
  1006. + dev_err(&hub->sdev->dev, "failed to query KIP connection state: %d\n", status);
  1007. + return status;
  1008. + }
  1009. +
  1010. + *state = connected ? SSAM_HUB_CONNECTED : SSAM_HUB_DISCONNECTED;
  1011. + return 0;
  1012. +}
  1013. +
  1014. +static u32 ssam_kip_hub_notif(struct ssam_event_notifier *nf, const struct ssam_event *event)
  1015. +{
  1016. + struct ssam_hub *hub = container_of(nf, struct ssam_hub, notif);
  1017. +
  1018. + if (event->command_id != SSAM_EVENT_KIP_CID_CONNECTION)
  1019. + return 0; /* Return "unhandled". */
  1020. +
  1021. + if (event->length < 1) {
  1022. + dev_err(&hub->sdev->dev, "unexpected payload size: %u\n", event->length);
  1023. + return 0;
  1024. + }
  1025. +
  1026. + ssam_hub_update(hub, event->data[0]);
  1027. + return SSAM_NOTIF_HANDLED;
  1028. +}
  1029. +
  1030. +static int ssam_kip_hub_probe(struct ssam_device *sdev)
  1031. +{
  1032. + struct ssam_hub *hub;
  1033. +
  1034. + hub = devm_kzalloc(&sdev->dev, sizeof(*hub), GFP_KERNEL);
  1035. + if (!hub)
  1036. + return -ENOMEM;
  1037. +
  1038. + hub->notif.base.priority = INT_MAX; /* This notifier should run first. */
  1039. + hub->notif.base.fn = ssam_kip_hub_notif;
  1040. + hub->notif.event.reg = SSAM_EVENT_REGISTRY_SAM;
  1041. + hub->notif.event.id.target_category = SSAM_SSH_TC_KIP,
  1042. + hub->notif.event.id.instance = 0,
  1043. + hub->notif.event.mask = SSAM_EVENT_MASK_TARGET;
  1044. + hub->notif.event.flags = SSAM_EVENT_SEQUENCED;
  1045. +
  1046. + hub->connect_delay = SSAM_KIP_UPDATE_CONNECT_DELAY;
  1047. + hub->get_state = ssam_kip_get_connection_state;
  1048. +
  1049. + return ssam_hub_setup(sdev, hub);
  1050. +}
  1051. +
  1052. +static const struct ssam_device_id ssam_kip_hub_match[] = {
  1053. + { SSAM_SDEV(KIP, 0x01, 0x00, 0x00) },
  1054. + { },
  1055. +};
  1056. +
  1057. +static struct ssam_device_driver ssam_kip_hub_driver = {
  1058. + .probe = ssam_kip_hub_probe,
  1059. + .remove = ssam_hub_remove,
  1060. + .match_table = ssam_kip_hub_match,
  1061. + .driver = {
  1062. + .name = "surface_kip_hub",
  1063. + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1064. + .pm = &ssam_hub_pm_ops,
  1065. + },
  1066. +};
  1067. +
  1068. +
  1069. /* -- SSAM platform/meta-hub driver. ---------------------------------------- */
  1070. static const struct acpi_device_id ssam_platform_hub_match[] = {
  1071. @@ -673,18 +760,30 @@ static int __init ssam_device_hub_init(void)
  1072. status = platform_driver_register(&ssam_platform_hub_driver);
  1073. if (status)
  1074. - return status;
  1075. + goto err_platform;
  1076. status = ssam_device_driver_register(&ssam_base_hub_driver);
  1077. if (status)
  1078. - platform_driver_unregister(&ssam_platform_hub_driver);
  1079. + goto err_base;
  1080. +
  1081. + status = ssam_device_driver_register(&ssam_kip_hub_driver);
  1082. + if (status)
  1083. + goto err_kip;
  1084. + return 0;
  1085. +
  1086. +err_kip:
  1087. + ssam_device_driver_unregister(&ssam_base_hub_driver);
  1088. +err_base:
  1089. + platform_driver_unregister(&ssam_platform_hub_driver);
  1090. +err_platform:
  1091. return status;
  1092. }
  1093. module_init(ssam_device_hub_init);
  1094. static void __exit ssam_device_hub_exit(void)
  1095. {
  1096. + ssam_device_driver_unregister(&ssam_kip_hub_driver);
  1097. ssam_device_driver_unregister(&ssam_base_hub_driver);
  1098. platform_driver_unregister(&ssam_platform_hub_driver);
  1099. }
  1100. --
  1101. 2.36.1
  1102. From 335ecc69e57311afd8329349024a0a2c9bc48a69 Mon Sep 17 00:00:00 2001
  1103. From: Maximilian Luz <luzmaximilian@gmail.com>
  1104. Date: Wed, 27 Oct 2021 22:33:03 +0200
  1105. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  1106. keyboard cover on Surface Pro 8
  1107. Add support for the detachable keyboard cover on the Surface Pro 8.
  1108. The keyboard cover on the Surface Pro 8 is, unlike the keyboard covers
  1109. of earlier Surface Pro generations, handled via the Surface System
  1110. Aggregator Module (SSAM). The keyboard and touchpad (as well as other
  1111. HID input devices) of this cover are standard SSAM HID client devices
  1112. (just like keyboard and touchpad on e.g. the Surface Laptop 3 and 4),
  1113. however, some care needs to be taken as they can be physically detached
  1114. (similarly to the Surface Book 3). Specifically, the respective SSAM
  1115. client devices need to be removed when the keyboard cover has been
  1116. detached and (re-)initialized when the keyboard cover has been
  1117. (re-)attached.
  1118. On the Surface Pro 8, detachment of the keyboard cover (and by extension
  1119. its devices) is managed via the KIP subsystem. Therefore, said devices
  1120. need to be registered under the KIP device hub, which in turn will
  1121. remove and re-create/re-initialize those devices as needed.
  1122. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1123. Patchset: surface-sam
  1124. ---
  1125. .../surface/surface_aggregator_registry.c | 37 ++++++++++++++++++-
  1126. 1 file changed, 36 insertions(+), 1 deletion(-)
  1127. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  1128. index 1e60435c7cce..ab69669316bd 100644
  1129. --- a/drivers/platform/surface/surface_aggregator_registry.c
  1130. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  1131. @@ -47,6 +47,12 @@ static const struct software_node ssam_node_hub_base = {
  1132. .parent = &ssam_node_root,
  1133. };
  1134. +/* KIP device hub (connects keyboard cover devices on Surface Pro 8). */
  1135. +static const struct software_node ssam_node_hub_kip = {
  1136. + .name = "ssam:01:0e:01:00:00",
  1137. + .parent = &ssam_node_root,
  1138. +};
  1139. +
  1140. /* AC adapter. */
  1141. static const struct software_node ssam_node_bat_ac = {
  1142. .name = "ssam:01:02:01:01:01",
  1143. @@ -155,6 +161,30 @@ static const struct software_node ssam_node_hid_base_iid6 = {
  1144. .parent = &ssam_node_hub_base,
  1145. };
  1146. +/* HID keyboard (KIP hub). */
  1147. +static const struct software_node ssam_node_hid_kip_keyboard = {
  1148. + .name = "ssam:01:15:02:01:00",
  1149. + .parent = &ssam_node_hub_kip,
  1150. +};
  1151. +
  1152. +/* HID pen stash (KIP hub; pen taken / stashed away evens). */
  1153. +static const struct software_node ssam_node_hid_kip_penstash = {
  1154. + .name = "ssam:01:15:02:02:00",
  1155. + .parent = &ssam_node_hub_kip,
  1156. +};
  1157. +
  1158. +/* HID touchpad (KIP hub). */
  1159. +static const struct software_node ssam_node_hid_kip_touchpad = {
  1160. + .name = "ssam:01:15:02:03:00",
  1161. + .parent = &ssam_node_hub_kip,
  1162. +};
  1163. +
  1164. +/* HID device instance 5 (KIP hub, unknown HID device). */
  1165. +static const struct software_node ssam_node_hid_kip_iid5 = {
  1166. + .name = "ssam:01:15:02:05:00",
  1167. + .parent = &ssam_node_hub_kip,
  1168. +};
  1169. +
  1170. /*
  1171. * Devices for 5th- and 6th-generations models:
  1172. * - Surface Book 2,
  1173. @@ -230,10 +260,15 @@ static const struct software_node *ssam_node_group_sp7[] = {
  1174. static const struct software_node *ssam_node_group_sp8[] = {
  1175. &ssam_node_root,
  1176. + &ssam_node_hub_kip,
  1177. &ssam_node_bat_ac,
  1178. &ssam_node_bat_main,
  1179. &ssam_node_tmp_pprof,
  1180. - /* TODO: Add support for keyboard cover. */
  1181. + &ssam_node_hid_kip_keyboard,
  1182. + &ssam_node_hid_kip_penstash,
  1183. + &ssam_node_hid_kip_touchpad,
  1184. + &ssam_node_hid_kip_iid5,
  1185. + /* TODO: Add support for tablet mode switch. */
  1186. NULL,
  1187. };
  1188. --
  1189. 2.36.1
  1190. From bbe7fdf41aa6efaa42b327eb9b399eb09532e593 Mon Sep 17 00:00:00 2001
  1191. From: Maximilian Luz <luzmaximilian@gmail.com>
  1192. Date: Tue, 8 Jun 2021 03:19:20 +0200
  1193. Subject: [PATCH] platform/surface: Add KIP tablet-mode switch
  1194. Add a driver providing a tablet-mode switch input device for Surface
  1195. models using the KIP subsystem to manage detachable peripherals.
  1196. The Surface Pro 8 has a detachable keyboard cover. Unlike the keyboard
  1197. covers of previous generation Surface Pro models, this cover is fully
  1198. handled by the Surface System Aggregator Module (SSAM). The SSAM KIP
  1199. subsystem (full name unknown, abbreviation found through reverse
  1200. engineering) provides notifications for mode changes of the cover.
  1201. Specifically, it allows us to know when the cover has been folded back,
  1202. detached, or whether it is in laptop mode.
  1203. The driver introduced with this change captures these events and
  1204. translates them to standard SW_TABLET_MODE input events.
  1205. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1206. Patchset: surface-sam
  1207. ---
  1208. MAINTAINERS | 6 +
  1209. drivers/platform/surface/Kconfig | 22 ++
  1210. drivers/platform/surface/Makefile | 1 +
  1211. .../surface/surface_kip_tablet_switch.c | 245 ++++++++++++++++++
  1212. 4 files changed, 274 insertions(+)
  1213. create mode 100644 drivers/platform/surface/surface_kip_tablet_switch.c
  1214. diff --git a/MAINTAINERS b/MAINTAINERS
  1215. index d9b2f1731ee0..4d83cd26e299 100644
  1216. --- a/MAINTAINERS
  1217. +++ b/MAINTAINERS
  1218. @@ -12823,6 +12823,12 @@ L: platform-driver-x86@vger.kernel.org
  1219. S: Maintained
  1220. F: drivers/platform/surface/surface_hotplug.c
  1221. +MICROSOFT SURFACE KIP TABLET-MODE SWITCH
  1222. +M: Maximilian Luz <luzmaximilian@gmail.com>
  1223. +L: platform-driver-x86@vger.kernel.org
  1224. +S: Maintained
  1225. +F: drivers/platform/surface/surface_kip_tablet_switch.c
  1226. +
  1227. MICROSOFT SURFACE PLATFORM PROFILE DRIVER
  1228. M: Maximilian Luz <luzmaximilian@gmail.com>
  1229. L: platform-driver-x86@vger.kernel.org
  1230. diff --git a/drivers/platform/surface/Kconfig b/drivers/platform/surface/Kconfig
  1231. index 463f1ec5c14e..9c228090c35b 100644
  1232. --- a/drivers/platform/surface/Kconfig
  1233. +++ b/drivers/platform/surface/Kconfig
  1234. @@ -156,6 +156,28 @@ config SURFACE_HOTPLUG
  1235. Select M or Y here, if you want to (fully) support hot-plugging of
  1236. dGPU devices on the Surface Book 2 and/or 3 during D3cold.
  1237. +config SURFACE_KIP_TABLET_SWITCH
  1238. + tristate "Surface KIP Tablet-Mode Switch Driver"
  1239. + depends on SURFACE_AGGREGATOR
  1240. + depends on SURFACE_AGGREGATOR_BUS
  1241. + depends on INPUT
  1242. + help
  1243. + Provides a tablet-mode switch input device on Microsoft Surface models
  1244. + using the KIP subsystem for detachable keyboards (e.g. keyboard
  1245. + covers).
  1246. +
  1247. + The KIP subsystem is used on newer Surface generations to handle
  1248. + detachable input peripherals, specifically the keyboard cover
  1249. + (containing keyboard and touchpad) on the Surface Pro 8. This module
  1250. + provides a driver to let user-space know when the device should be
  1251. + considered in tablet-mode due to the keyboard cover being detached or
  1252. + folded back (essentially signaling when the keyboard is not available
  1253. + for input). It does so by creating a tablet-mode switch input device,
  1254. + sending the standard SW_TABLET_MODE event on mode change.
  1255. +
  1256. + Select M or Y here, if you want to provide tablet-mode switch input
  1257. + events on the Surface Pro 8.
  1258. +
  1259. config SURFACE_PLATFORM_PROFILE
  1260. tristate "Surface Platform Profile Driver"
  1261. depends on ACPI
  1262. diff --git a/drivers/platform/surface/Makefile b/drivers/platform/surface/Makefile
  1263. index 32889482de55..6d9291c993c4 100644
  1264. --- a/drivers/platform/surface/Makefile
  1265. +++ b/drivers/platform/surface/Makefile
  1266. @@ -14,5 +14,6 @@ obj-$(CONFIG_SURFACE_AGGREGATOR_REGISTRY) += surface_aggregator_registry.o
  1267. obj-$(CONFIG_SURFACE_DTX) += surface_dtx.o
  1268. obj-$(CONFIG_SURFACE_GPE) += surface_gpe.o
  1269. obj-$(CONFIG_SURFACE_HOTPLUG) += surface_hotplug.o
  1270. +obj-$(CONFIG_SURFACE_KIP_TABLET_SWITCH) += surface_kip_tablet_switch.o
  1271. obj-$(CONFIG_SURFACE_PLATFORM_PROFILE) += surface_platform_profile.o
  1272. obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o
  1273. diff --git a/drivers/platform/surface/surface_kip_tablet_switch.c b/drivers/platform/surface/surface_kip_tablet_switch.c
  1274. new file mode 100644
  1275. index 000000000000..27371da71ef2
  1276. --- /dev/null
  1277. +++ b/drivers/platform/surface/surface_kip_tablet_switch.c
  1278. @@ -0,0 +1,245 @@
  1279. +// SPDX-License-Identifier: GPL-2.0+
  1280. +/*
  1281. + * Surface System Aggregator Module (SSAM) tablet mode switch via KIP
  1282. + * subsystem.
  1283. + *
  1284. + * Copyright (C) 2022 Maximilian Luz <luzmaximilian@gmail.com>
  1285. + */
  1286. +
  1287. +#include <linux/input.h>
  1288. +#include <linux/kernel.h>
  1289. +#include <linux/module.h>
  1290. +#include <linux/platform_device.h>
  1291. +#include <linux/types.h>
  1292. +#include <linux/workqueue.h>
  1293. +
  1294. +#include <linux/surface_aggregator/controller.h>
  1295. +#include <linux/surface_aggregator/device.h>
  1296. +
  1297. +#define SSAM_EVENT_KIP_CID_LID_STATE 0x1d
  1298. +
  1299. +enum ssam_kip_lid_state {
  1300. + SSAM_KIP_LID_STATE_DISCONNECTED = 0x01,
  1301. + SSAM_KIP_LID_STATE_CLOSED = 0x02,
  1302. + SSAM_KIP_LID_STATE_LAPTOP = 0x03,
  1303. + SSAM_KIP_LID_STATE_FOLDED_CANVAS = 0x04,
  1304. + SSAM_KIP_LID_STATE_FOLDED_BACK = 0x05,
  1305. +};
  1306. +
  1307. +struct ssam_kip_sw {
  1308. + struct ssam_device *sdev;
  1309. +
  1310. + enum ssam_kip_lid_state state;
  1311. + struct work_struct update_work;
  1312. + struct input_dev *mode_switch;
  1313. +
  1314. + struct ssam_event_notifier notif;
  1315. +};
  1316. +
  1317. +SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_get_lid_state, u8, {
  1318. + .target_category = SSAM_SSH_TC_KIP,
  1319. + .target_id = 0x01,
  1320. + .command_id = 0x1d,
  1321. + .instance_id = 0x00,
  1322. +});
  1323. +
  1324. +static int ssam_kip_get_lid_state(struct ssam_kip_sw *sw, enum ssam_kip_lid_state *state)
  1325. +{
  1326. + int status;
  1327. + u8 raw;
  1328. +
  1329. + status = ssam_retry(__ssam_kip_get_lid_state, sw->sdev->ctrl, &raw);
  1330. + if (status < 0) {
  1331. + dev_err(&sw->sdev->dev, "failed to query KIP lid state: %d\n", status);
  1332. + return status;
  1333. + }
  1334. +
  1335. + *state = raw;
  1336. + return 0;
  1337. +}
  1338. +
  1339. +static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf)
  1340. +{
  1341. + struct ssam_kip_sw *sw = dev_get_drvdata(dev);
  1342. + const char *state;
  1343. +
  1344. + switch (sw->state) {
  1345. + case SSAM_KIP_LID_STATE_DISCONNECTED:
  1346. + state = "disconnected";
  1347. + break;
  1348. +
  1349. + case SSAM_KIP_LID_STATE_CLOSED:
  1350. + state = "closed";
  1351. + break;
  1352. +
  1353. + case SSAM_KIP_LID_STATE_LAPTOP:
  1354. + state = "laptop";
  1355. + break;
  1356. +
  1357. + case SSAM_KIP_LID_STATE_FOLDED_CANVAS:
  1358. + state = "folded-canvas";
  1359. + break;
  1360. +
  1361. + case SSAM_KIP_LID_STATE_FOLDED_BACK:
  1362. + state = "folded-back";
  1363. + break;
  1364. +
  1365. + default:
  1366. + state = "<unknown>";
  1367. + dev_warn(dev, "unknown KIP lid state: %d\n", sw->state);
  1368. + break;
  1369. + }
  1370. +
  1371. + return sysfs_emit(buf, "%s\n", state);
  1372. +}
  1373. +static DEVICE_ATTR_RO(state);
  1374. +
  1375. +static struct attribute *ssam_kip_sw_attrs[] = {
  1376. + &dev_attr_state.attr,
  1377. + NULL,
  1378. +};
  1379. +
  1380. +static const struct attribute_group ssam_kip_sw_group = {
  1381. + .attrs = ssam_kip_sw_attrs,
  1382. +};
  1383. +
  1384. +static void ssam_kip_sw_update_workfn(struct work_struct *work)
  1385. +{
  1386. + struct ssam_kip_sw *sw = container_of(work, struct ssam_kip_sw, update_work);
  1387. + enum ssam_kip_lid_state state;
  1388. + int tablet, status;
  1389. +
  1390. + status = ssam_kip_get_lid_state(sw, &state);
  1391. + if (status)
  1392. + return;
  1393. +
  1394. + if (sw->state == state)
  1395. + return;
  1396. + sw->state = state;
  1397. +
  1398. + /* Send SW_TABLET_MODE event. */
  1399. + tablet = state != SSAM_KIP_LID_STATE_LAPTOP;
  1400. + input_report_switch(sw->mode_switch, SW_TABLET_MODE, tablet);
  1401. + input_sync(sw->mode_switch);
  1402. +}
  1403. +
  1404. +static u32 ssam_kip_sw_notif(struct ssam_event_notifier *nf, const struct ssam_event *event)
  1405. +{
  1406. + struct ssam_kip_sw *sw = container_of(nf, struct ssam_kip_sw, notif);
  1407. +
  1408. + if (event->command_id != SSAM_EVENT_KIP_CID_LID_STATE)
  1409. + return 0; /* Return "unhandled". */
  1410. +
  1411. + if (event->length < 1) {
  1412. + dev_err(&sw->sdev->dev, "unexpected payload size: %u\n", event->length);
  1413. + return 0;
  1414. + }
  1415. +
  1416. + schedule_work(&sw->update_work);
  1417. + return SSAM_NOTIF_HANDLED;
  1418. +}
  1419. +
  1420. +static int __maybe_unused ssam_kip_sw_resume(struct device *dev)
  1421. +{
  1422. + struct ssam_kip_sw *sw = dev_get_drvdata(dev);
  1423. +
  1424. + schedule_work(&sw->update_work);
  1425. + return 0;
  1426. +}
  1427. +static SIMPLE_DEV_PM_OPS(ssam_kip_sw_pm_ops, NULL, ssam_kip_sw_resume);
  1428. +
  1429. +static int ssam_kip_sw_probe(struct ssam_device *sdev)
  1430. +{
  1431. + struct ssam_kip_sw *sw;
  1432. + int tablet, status;
  1433. +
  1434. + sw = devm_kzalloc(&sdev->dev, sizeof(*sw), GFP_KERNEL);
  1435. + if (!sw)
  1436. + return -ENOMEM;
  1437. +
  1438. + sw->sdev = sdev;
  1439. + INIT_WORK(&sw->update_work, ssam_kip_sw_update_workfn);
  1440. +
  1441. + ssam_device_set_drvdata(sdev, sw);
  1442. +
  1443. + /* Get initial state. */
  1444. + status = ssam_kip_get_lid_state(sw, &sw->state);
  1445. + if (status)
  1446. + return status;
  1447. +
  1448. + /* Set up tablet mode switch. */
  1449. + sw->mode_switch = devm_input_allocate_device(&sdev->dev);
  1450. + if (!sw->mode_switch)
  1451. + return -ENOMEM;
  1452. +
  1453. + sw->mode_switch->name = "Microsoft Surface KIP Tablet Mode Switch";
  1454. + sw->mode_switch->phys = "ssam/01:0e:01:00:01/input0";
  1455. + sw->mode_switch->id.bustype = BUS_HOST;
  1456. + sw->mode_switch->dev.parent = &sdev->dev;
  1457. +
  1458. + tablet = sw->state != SSAM_KIP_LID_STATE_LAPTOP;
  1459. + input_set_capability(sw->mode_switch, EV_SW, SW_TABLET_MODE);
  1460. + input_report_switch(sw->mode_switch, SW_TABLET_MODE, tablet);
  1461. +
  1462. + status = input_register_device(sw->mode_switch);
  1463. + if (status)
  1464. + return status;
  1465. +
  1466. + /* Set up notifier. */
  1467. + sw->notif.base.priority = 0;
  1468. + sw->notif.base.fn = ssam_kip_sw_notif;
  1469. + sw->notif.event.reg = SSAM_EVENT_REGISTRY_SAM;
  1470. + sw->notif.event.id.target_category = SSAM_SSH_TC_KIP,
  1471. + sw->notif.event.id.instance = 0,
  1472. + sw->notif.event.mask = SSAM_EVENT_MASK_TARGET;
  1473. + sw->notif.event.flags = SSAM_EVENT_SEQUENCED;
  1474. +
  1475. + status = ssam_device_notifier_register(sdev, &sw->notif);
  1476. + if (status)
  1477. + return status;
  1478. +
  1479. + status = sysfs_create_group(&sdev->dev.kobj, &ssam_kip_sw_group);
  1480. + if (status)
  1481. + goto err;
  1482. +
  1483. + /* We might have missed events during setup, so check again. */
  1484. + schedule_work(&sw->update_work);
  1485. + return 0;
  1486. +
  1487. +err:
  1488. + ssam_device_notifier_unregister(sdev, &sw->notif);
  1489. + cancel_work_sync(&sw->update_work);
  1490. + return status;
  1491. +}
  1492. +
  1493. +static void ssam_kip_sw_remove(struct ssam_device *sdev)
  1494. +{
  1495. + struct ssam_kip_sw *sw = ssam_device_get_drvdata(sdev);
  1496. +
  1497. + sysfs_remove_group(&sdev->dev.kobj, &ssam_kip_sw_group);
  1498. +
  1499. + ssam_device_notifier_unregister(sdev, &sw->notif);
  1500. + cancel_work_sync(&sw->update_work);
  1501. +}
  1502. +
  1503. +static const struct ssam_device_id ssam_kip_sw_match[] = {
  1504. + { SSAM_SDEV(KIP, 0x01, 0x00, 0x01) },
  1505. + { },
  1506. +};
  1507. +MODULE_DEVICE_TABLE(ssam, ssam_kip_sw_match);
  1508. +
  1509. +static struct ssam_device_driver ssam_kip_sw_driver = {
  1510. + .probe = ssam_kip_sw_probe,
  1511. + .remove = ssam_kip_sw_remove,
  1512. + .match_table = ssam_kip_sw_match,
  1513. + .driver = {
  1514. + .name = "surface_kip_tablet_mode_switch",
  1515. + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1516. + .pm = &ssam_kip_sw_pm_ops,
  1517. + },
  1518. +};
  1519. +module_ssam_device_driver(ssam_kip_sw_driver);
  1520. +
  1521. +MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
  1522. +MODULE_DESCRIPTION("Tablet mode switch driver for Surface devices using KIP subsystem");
  1523. +MODULE_LICENSE("GPL");
  1524. --
  1525. 2.36.1
  1526. From d60c4b561fd96cc78ae0a4513008a2c61cdfa7b9 Mon Sep 17 00:00:00 2001
  1527. From: Maximilian Luz <luzmaximilian@gmail.com>
  1528. Date: Wed, 27 Oct 2021 22:33:03 +0200
  1529. Subject: [PATCH] platform/surface: aggregator_registry: Add support for tablet
  1530. mode switch on Surface Pro 8
  1531. Add a KIP subsystem tablet-mode switch device for the Surface Pro 8.
  1532. The respective driver for this device provides SW_TABLET_MODE input
  1533. events for user-space based on the state of the keyboard cover (e.g.
  1534. detached, folded-back, normal/laptop mode).
  1535. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1536. Patchset: surface-sam
  1537. ---
  1538. drivers/platform/surface/surface_aggregator_registry.c | 8 +++++++-
  1539. 1 file changed, 7 insertions(+), 1 deletion(-)
  1540. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  1541. index ab69669316bd..c666392d4a9a 100644
  1542. --- a/drivers/platform/surface/surface_aggregator_registry.c
  1543. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  1544. @@ -77,6 +77,12 @@ static const struct software_node ssam_node_tmp_pprof = {
  1545. .parent = &ssam_node_root,
  1546. };
  1547. +/* Tablet-mode switch via KIP subsystem. */
  1548. +static const struct software_node ssam_node_kip_tablet_switch = {
  1549. + .name = "ssam:01:0e:01:00:01",
  1550. + .parent = &ssam_node_root,
  1551. +};
  1552. +
  1553. /* DTX / detachment-system device (Surface Book 3). */
  1554. static const struct software_node ssam_node_bas_dtx = {
  1555. .name = "ssam:01:11:01:00:00",
  1556. @@ -264,11 +270,11 @@ static const struct software_node *ssam_node_group_sp8[] = {
  1557. &ssam_node_bat_ac,
  1558. &ssam_node_bat_main,
  1559. &ssam_node_tmp_pprof,
  1560. + &ssam_node_kip_tablet_switch,
  1561. &ssam_node_hid_kip_keyboard,
  1562. &ssam_node_hid_kip_penstash,
  1563. &ssam_node_hid_kip_touchpad,
  1564. &ssam_node_hid_kip_iid5,
  1565. - /* TODO: Add support for tablet mode switch. */
  1566. NULL,
  1567. };
  1568. --
  1569. 2.36.1
  1570. From 823f673da298f4a1b6b088c7a9d54b9c5faa180a Mon Sep 17 00:00:00 2001
  1571. From: Maximilian Luz <luzmaximilian@gmail.com>
  1572. Date: Sat, 21 May 2022 00:30:46 +0200
  1573. Subject: [PATCH] platform/surface: aggregator: Move device registry helper
  1574. function to core module
  1575. Move helper functions for client device registration to the core module.
  1576. This simplifies addition of future DT/OF support and also allows us to
  1577. split out the device hub drivers into their own module.
  1578. At the same time, also improve device node validation a bit by not
  1579. silently skipping devices with invalid device UID specifiers.
  1580. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1581. Patchset: surface-sam
  1582. ---
  1583. drivers/platform/surface/aggregator/bus.c | 176 ++++++++++++++++--
  1584. .../surface/surface_aggregator_registry.c | 75 +-------
  1585. include/linux/surface_aggregator/device.h | 37 ++++
  1586. 3 files changed, 199 insertions(+), 89 deletions(-)
  1587. diff --git a/drivers/platform/surface/aggregator/bus.c b/drivers/platform/surface/aggregator/bus.c
  1588. index abbbb5b08b07..4bba60884bb5 100644
  1589. --- a/drivers/platform/surface/aggregator/bus.c
  1590. +++ b/drivers/platform/surface/aggregator/bus.c
  1591. @@ -6,6 +6,7 @@
  1592. */
  1593. #include <linux/device.h>
  1594. +#include <linux/property.h>
  1595. #include <linux/slab.h>
  1596. #include <linux/surface_aggregator/controller.h>
  1597. @@ -14,6 +15,9 @@
  1598. #include "bus.h"
  1599. #include "controller.h"
  1600. +
  1601. +/* -- Device and bus functions. --------------------------------------------- */
  1602. +
  1603. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  1604. char *buf)
  1605. {
  1606. @@ -363,6 +367,162 @@ void ssam_device_driver_unregister(struct ssam_device_driver *sdrv)
  1607. }
  1608. EXPORT_SYMBOL_GPL(ssam_device_driver_unregister);
  1609. +
  1610. +/* -- Bus registration. ----------------------------------------------------- */
  1611. +
  1612. +/**
  1613. + * ssam_bus_register() - Register and set-up the SSAM client device bus.
  1614. + */
  1615. +int ssam_bus_register(void)
  1616. +{
  1617. + return bus_register(&ssam_bus_type);
  1618. +}
  1619. +
  1620. +/**
  1621. + * ssam_bus_unregister() - Unregister the SSAM client device bus.
  1622. + */
  1623. +void ssam_bus_unregister(void)
  1624. +{
  1625. + return bus_unregister(&ssam_bus_type);
  1626. +}
  1627. +
  1628. +
  1629. +/* -- Helpers for controller and hub devices. ------------------------------- */
  1630. +
  1631. +static int ssam_device_uid_from_string(const char *str, struct ssam_device_uid *uid)
  1632. +{
  1633. + u8 d, tc, tid, iid, fn;
  1634. + int n;
  1635. +
  1636. + n = sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx", &d, &tc, &tid, &iid, &fn);
  1637. + if (n != 5)
  1638. + return -EINVAL;
  1639. +
  1640. + uid->domain = d;
  1641. + uid->category = tc;
  1642. + uid->target = tid;
  1643. + uid->instance = iid;
  1644. + uid->function = fn;
  1645. +
  1646. + return 0;
  1647. +}
  1648. +
  1649. +static int ssam_get_uid_for_node(struct fwnode_handle *node, struct ssam_device_uid *uid)
  1650. +{
  1651. + const char* str = fwnode_get_name(node);
  1652. +
  1653. + /*
  1654. + * To simplify definitions of firmware nodes, we set the device name
  1655. + * based on the UID of the device, prefixed with "ssam:".
  1656. + */
  1657. + if (strncmp(str, "ssam:", strlen("ssam:")) != 0)
  1658. + return -ENODEV;
  1659. +
  1660. + str += strlen("ssam:");
  1661. + return ssam_device_uid_from_string(str, uid);
  1662. +}
  1663. +
  1664. +static int ssam_add_client_device(struct device *parent, struct ssam_controller *ctrl,
  1665. + struct fwnode_handle *node)
  1666. +{
  1667. + struct ssam_device_uid uid;
  1668. + struct ssam_device *sdev;
  1669. + int status;
  1670. +
  1671. + status = ssam_get_uid_for_node(node, &uid);
  1672. + if (status)
  1673. + return status;
  1674. +
  1675. + sdev = ssam_device_alloc(ctrl, uid);
  1676. + if (!sdev)
  1677. + return -ENOMEM;
  1678. +
  1679. + sdev->dev.parent = parent;
  1680. + sdev->dev.fwnode = node;
  1681. +
  1682. + status = ssam_device_add(sdev);
  1683. + if (status)
  1684. + ssam_device_put(sdev);
  1685. +
  1686. + return status;
  1687. +}
  1688. +
  1689. +/**
  1690. + * __ssam_register_clients() - Register client devices defined under the
  1691. + * given firmware node as children of the given device.
  1692. + * @parent: The parent device under which clients should be registered.
  1693. + * @ctrl: The controller with which client should be registered.
  1694. + * @node: The firmware node holding definitions of the devices to be added.
  1695. + *
  1696. + * Register all clients that have been defined as children of the given root
  1697. + * firmware node as children of the given parent device. The respective child
  1698. + * firmware nodes will be associated with the correspondingly created child
  1699. + * devices.
  1700. + *
  1701. + * The given controller will be used to instantiate the new devices. See
  1702. + * ssam_device_add() for details.
  1703. + *
  1704. + * Note that, generally, the use of either ssam_device_register_clients() or
  1705. + * ssam_register_clients() should be preferred as they directly use the
  1706. + * firmware node and/or controller associated with the given device. This
  1707. + * function is only intended for use when different device specifications (e.g.
  1708. + * ACPI and firmware nodes) need to be combined (as is done in the platform hub
  1709. + * of the device registry).
  1710. + *
  1711. + * Return: Returns zero on success, nonzero on failure.
  1712. + */
  1713. +int __ssam_register_clients(struct device *parent, struct ssam_controller *ctrl,
  1714. + struct fwnode_handle *node)
  1715. +{
  1716. + struct fwnode_handle *child;
  1717. + int status;
  1718. +
  1719. + fwnode_for_each_child_node(node, child) {
  1720. + /*
  1721. + * Try to add the device specified in the firmware node. If
  1722. + * this fails with -ENODEV, the node does not specify any SSAM
  1723. + * device, so ignore it and continue with the next one.
  1724. + */
  1725. + status = ssam_add_client_device(parent, ctrl, child);
  1726. + if (status && status != -ENODEV)
  1727. + goto err;
  1728. + }
  1729. +
  1730. + return 0;
  1731. +err:
  1732. + ssam_remove_clients(parent);
  1733. + return status;
  1734. +}
  1735. +EXPORT_SYMBOL_GPL(__ssam_register_clients);
  1736. +
  1737. +/**
  1738. + * ssam_register_clients() - Register all client devices defined under the
  1739. + * given parent device.
  1740. + * @dev: The parent device under which clients should be registered.
  1741. + * @ctrl: The controller with which client should be registered.
  1742. + *
  1743. + * Register all clients that have via firmware nodes been defined as children
  1744. + * of the given (parent) device. The respective child firmware nodes will be
  1745. + * associated with the correspondingly created child devices.
  1746. + *
  1747. + * The given controller will be used to instantiate the new devices. See
  1748. + * ssam_device_add() for details.
  1749. + *
  1750. + * Return: Returns zero on success, nonzero on failure.
  1751. + */
  1752. +int ssam_register_clients(struct device *dev, struct ssam_controller *ctrl)
  1753. +{
  1754. + struct fwnode_handle *node;
  1755. + int status;
  1756. +
  1757. + node = fwnode_handle_get(dev_fwnode(dev));
  1758. + status = __ssam_register_clients(dev, ctrl, node);
  1759. + fwnode_handle_put(node);
  1760. +
  1761. + return status;
  1762. +}
  1763. +EXPORT_SYMBOL_GPL(ssam_register_clients);
  1764. +
  1765. static int ssam_remove_device(struct device *dev, void *_data)
  1766. {
  1767. struct ssam_device *sdev = to_ssam_device(dev);
  1768. @@ -387,19 +547,3 @@ void ssam_remove_clients(struct device *dev)
  1769. device_for_each_child_reverse(dev, NULL, ssam_remove_device);
  1770. }
  1771. EXPORT_SYMBOL_GPL(ssam_remove_clients);
  1772. -
  1773. -/**
  1774. - * ssam_bus_register() - Register and set-up the SSAM client device bus.
  1775. - */
  1776. -int ssam_bus_register(void)
  1777. -{
  1778. - return bus_register(&ssam_bus_type);
  1779. -}
  1780. -
  1781. -/**
  1782. - * ssam_bus_unregister() - Unregister the SSAM client device bus.
  1783. - */
  1784. -void ssam_bus_unregister(void)
  1785. -{
  1786. - return bus_unregister(&ssam_bus_type);
  1787. -}
  1788. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  1789. index c666392d4a9a..3261c8141841 100644
  1790. --- a/drivers/platform/surface/surface_aggregator_registry.c
  1791. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  1792. @@ -279,76 +279,6 @@ static const struct software_node *ssam_node_group_sp8[] = {
  1793. };
  1794. -/* -- Device registry helper functions. ------------------------------------- */
  1795. -
  1796. -static int ssam_uid_from_string(const char *str, struct ssam_device_uid *uid)
  1797. -{
  1798. - u8 d, tc, tid, iid, fn;
  1799. - int n;
  1800. -
  1801. - n = sscanf(str, "ssam:%hhx:%hhx:%hhx:%hhx:%hhx", &d, &tc, &tid, &iid, &fn);
  1802. - if (n != 5)
  1803. - return -EINVAL;
  1804. -
  1805. - uid->domain = d;
  1806. - uid->category = tc;
  1807. - uid->target = tid;
  1808. - uid->instance = iid;
  1809. - uid->function = fn;
  1810. -
  1811. - return 0;
  1812. -}
  1813. -
  1814. -static int ssam_hub_add_device(struct device *parent, struct ssam_controller *ctrl,
  1815. - struct fwnode_handle *node)
  1816. -{
  1817. - struct ssam_device_uid uid;
  1818. - struct ssam_device *sdev;
  1819. - int status;
  1820. -
  1821. - status = ssam_uid_from_string(fwnode_get_name(node), &uid);
  1822. - if (status)
  1823. - return status;
  1824. -
  1825. - sdev = ssam_device_alloc(ctrl, uid);
  1826. - if (!sdev)
  1827. - return -ENOMEM;
  1828. -
  1829. - sdev->dev.parent = parent;
  1830. - sdev->dev.fwnode = node;
  1831. -
  1832. - status = ssam_device_add(sdev);
  1833. - if (status)
  1834. - ssam_device_put(sdev);
  1835. -
  1836. - return status;
  1837. -}
  1838. -
  1839. -static int ssam_hub_register_clients(struct device *parent, struct ssam_controller *ctrl,
  1840. - struct fwnode_handle *node)
  1841. -{
  1842. - struct fwnode_handle *child;
  1843. - int status;
  1844. -
  1845. - fwnode_for_each_child_node(node, child) {
  1846. - /*
  1847. - * Try to add the device specified in the firmware node. If
  1848. - * this fails with -EINVAL, the node does not specify any SSAM
  1849. - * device, so ignore it and continue with the next one.
  1850. - */
  1851. -
  1852. - status = ssam_hub_add_device(parent, ctrl, child);
  1853. - if (status && status != -EINVAL)
  1854. - goto err;
  1855. - }
  1856. -
  1857. - return 0;
  1858. -err:
  1859. - ssam_remove_clients(parent);
  1860. - return status;
  1861. -}
  1862. -
  1863. -
  1864. /* -- SSAM generic subsystem hub driver framework. -------------------------- */
  1865. enum ssam_hub_state {
  1866. @@ -378,7 +308,6 @@ struct ssam_hub {
  1867. static void ssam_hub_update_workfn(struct work_struct *work)
  1868. {
  1869. struct ssam_hub *hub = container_of(work, struct ssam_hub, update_work.work);
  1870. - struct fwnode_handle *node = dev_fwnode(&hub->sdev->dev);
  1871. enum ssam_hub_state state;
  1872. int status = 0;
  1873. @@ -418,7 +347,7 @@ static void ssam_hub_update_workfn(struct work_struct *work)
  1874. hub->state = state;
  1875. if (hub->state == SSAM_HUB_CONNECTED)
  1876. - status = ssam_hub_register_clients(&hub->sdev->dev, hub->sdev->ctrl, node);
  1877. + status = ssam_device_register_clients(hub->sdev);
  1878. else
  1879. ssam_remove_clients(&hub->sdev->dev);
  1880. @@ -762,7 +691,7 @@ static int ssam_platform_hub_probe(struct platform_device *pdev)
  1881. set_secondary_fwnode(&pdev->dev, root);
  1882. - status = ssam_hub_register_clients(&pdev->dev, ctrl, root);
  1883. + status = __ssam_register_clients(&pdev->dev, ctrl, root);
  1884. if (status) {
  1885. set_secondary_fwnode(&pdev->dev, NULL);
  1886. software_node_unregister_node_group(nodes);
  1887. diff --git a/include/linux/surface_aggregator/device.h b/include/linux/surface_aggregator/device.h
  1888. index ad245c6b00d0..6ae110e830b4 100644
  1889. --- a/include/linux/surface_aggregator/device.h
  1890. +++ b/include/linux/surface_aggregator/device.h
  1891. @@ -364,11 +364,48 @@ void ssam_device_driver_unregister(struct ssam_device_driver *d);
  1892. /* -- Helpers for controller and hub devices. ------------------------------- */
  1893. #ifdef CONFIG_SURFACE_AGGREGATOR_BUS
  1894. +
  1895. +int __ssam_register_clients(struct device *parent, struct ssam_controller *ctrl,
  1896. + struct fwnode_handle *node);
  1897. +int ssam_register_clients(struct device *dev, struct ssam_controller *ctrl);
  1898. void ssam_remove_clients(struct device *dev);
  1899. +
  1900. #else /* CONFIG_SURFACE_AGGREGATOR_BUS */
  1901. +
  1902. +static inline int __ssam_register_clients(struct device *parent, struct ssam_controller *ctrl,
  1903. + struct fwnode_handle *node)
  1904. +{
  1905. + return 0;
  1906. +}
  1907. +
  1908. +static inline int ssam_register_clients(struct device *dev, struct ssam_controller *ctrl)
  1909. +{
  1910. + return 0;
  1911. +}
  1912. +
  1913. static inline void ssam_remove_clients(struct device *dev) {}
  1914. +
  1915. #endif /* CONFIG_SURFACE_AGGREGATOR_BUS */
  1916. +/**
  1917. + * ssam_device_register_clients() - Register all client devices defined under
  1918. + * the given SSAM parent device.
  1919. + * @sdev: The parent device under which clients should be registered.
  1920. + *
  1921. + * Register all clients that have via firmware nodes been defined as children
  1922. + * of the given (parent) device. The respective child firmware nodes will be
  1923. + * associated with the correspondingly created child devices.
  1924. + *
  1925. + * The controller used by the parent device will be used to instantiate the new
  1926. + * devices. See ssam_device_add() for details.
  1927. + *
  1928. + * Return: Returns zero on success, nonzero on failure.
  1929. + */
  1930. +static inline int ssam_device_register_clients(struct ssam_device *sdev)
  1931. +{
  1932. + return ssam_register_clients(&sdev->dev, sdev->ctrl);
  1933. +}
  1934. +
  1935. /* -- Helpers for client-device requests. ----------------------------------- */
  1936. --
  1937. 2.36.1
  1938. From a3075f9716bfa922bbbe9cba0eb31835a5b613ad Mon Sep 17 00:00:00 2001
  1939. From: Maximilian Luz <luzmaximilian@gmail.com>
  1940. Date: Sat, 21 May 2022 00:39:56 +0200
  1941. Subject: [PATCH] platform/surface: aggregator: Move subsystem hub drivers to
  1942. their own module
  1943. Split out subsystem device hub drivers into their own module. This
  1944. allows us to load the hub drivers separately from the registry, which
  1945. will help future DT/OF support.
  1946. While doing so, also remove a small bit of code duplication.
  1947. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1948. Patchset: surface-sam
  1949. ---
  1950. drivers/platform/surface/Kconfig | 35 +-
  1951. drivers/platform/surface/Makefile | 1 +
  1952. .../platform/surface/surface_aggregator_hub.c | 363 +++++++++++++++++
  1953. .../surface/surface_aggregator_registry.c | 371 +-----------------
  1954. 4 files changed, 396 insertions(+), 374 deletions(-)
  1955. create mode 100644 drivers/platform/surface/surface_aggregator_hub.c
  1956. diff --git a/drivers/platform/surface/Kconfig b/drivers/platform/surface/Kconfig
  1957. index 9c228090c35b..c685ec440535 100644
  1958. --- a/drivers/platform/surface/Kconfig
  1959. +++ b/drivers/platform/surface/Kconfig
  1960. @@ -79,18 +79,45 @@ config SURFACE_AGGREGATOR_CDEV
  1961. The provided interface is intended for debugging and development only,
  1962. and should not be used otherwise.
  1963. +config SURFACE_AGGREGATOR_HUB
  1964. + tristate "Surface System Aggregator Module Subsystem Device Hubs"
  1965. + depends on SURFACE_AGGREGATOR
  1966. + depends on SURFACE_AGGREGATOR_BUS
  1967. + help
  1968. + Device-hub drivers for Surface System Aggregator Module (SSAM) subsystem
  1969. + devices.
  1970. +
  1971. + Provides subsystem hub drivers which manage client devices on various
  1972. + SSAM subsystems. In some subsystems, notably the BAS subsystem managing
  1973. + devices contained in the base of the Surface Book 3 and the KIP subsystem
  1974. + managing type-cover devices in the Surface Pro 8 and Surface Pro X,
  1975. + devices can be (hot-)removed. Hub devices and drivers are required to
  1976. + manage these subdevices.
  1977. +
  1978. + Devices managed via these hubs are:
  1979. + - Battery/AC devices (Surface Book 3).
  1980. + - HID input devices (7th-generation and later models with detachable
  1981. + input devices).
  1982. +
  1983. + Select M (recommended) or Y here if you want support for the above
  1984. + mentioned devices on the corresponding Surface models. Without this
  1985. + module, the respective devices mentioned above will not be instantiated
  1986. + and thus any functionality provided by them will be missing, even when
  1987. + drivers for these devices are present. This module only provides the
  1988. + respective subsystem hubs. Both drivers and device specification (e.g.
  1989. + via the Surface Aggregator Registry) for these devices still need to be
  1990. + selected via other options.
  1991. +
  1992. config SURFACE_AGGREGATOR_REGISTRY
  1993. tristate "Surface System Aggregator Module Device Registry"
  1994. depends on SURFACE_AGGREGATOR
  1995. depends on SURFACE_AGGREGATOR_BUS
  1996. help
  1997. - Device-registry and device-hubs for Surface System Aggregator Module
  1998. - (SSAM) devices.
  1999. + Device-registry for Surface System Aggregator Module (SSAM) devices.
  2000. Provides a module and driver which act as a device-registry for SSAM
  2001. client devices that cannot be detected automatically, e.g. via ACPI.
  2002. - Such devices are instead provided via this registry and attached via
  2003. - device hubs, also provided in this module.
  2004. + Such devices are instead provided and managed via this registry.
  2005. Devices provided via this registry are:
  2006. - Platform profile (performance-/cooling-mode) device (5th- and later
  2007. diff --git a/drivers/platform/surface/Makefile b/drivers/platform/surface/Makefile
  2008. index 6d9291c993c4..fccd33e6780d 100644
  2009. --- a/drivers/platform/surface/Makefile
  2010. +++ b/drivers/platform/surface/Makefile
  2011. @@ -10,6 +10,7 @@ obj-$(CONFIG_SURFACE_3_POWER_OPREGION) += surface3_power.o
  2012. obj-$(CONFIG_SURFACE_ACPI_NOTIFY) += surface_acpi_notify.o
  2013. obj-$(CONFIG_SURFACE_AGGREGATOR) += aggregator/
  2014. obj-$(CONFIG_SURFACE_AGGREGATOR_CDEV) += surface_aggregator_cdev.o
  2015. +obj-$(CONFIG_SURFACE_AGGREGATOR_HUB) += surface_aggregator_hub.o
  2016. obj-$(CONFIG_SURFACE_AGGREGATOR_REGISTRY) += surface_aggregator_registry.o
  2017. obj-$(CONFIG_SURFACE_DTX) += surface_dtx.o
  2018. obj-$(CONFIG_SURFACE_GPE) += surface_gpe.o
  2019. diff --git a/drivers/platform/surface/surface_aggregator_hub.c b/drivers/platform/surface/surface_aggregator_hub.c
  2020. new file mode 100644
  2021. index 000000000000..20b1c38debfe
  2022. --- /dev/null
  2023. +++ b/drivers/platform/surface/surface_aggregator_hub.c
  2024. @@ -0,0 +1,363 @@
  2025. +// SPDX-License-Identifier: GPL-2.0+
  2026. +/*
  2027. + * Driver for Surface System Aggregator Module (SSAM) subsystem device hubs.
  2028. + *
  2029. + * Provides a driver for SSAM subsystems device hubs. This driver performs
  2030. + * instantiation of the devices managed by said hubs and takes care of
  2031. + * (hot-)removal.
  2032. + *
  2033. + * Copyright (C) 2020-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2034. + */
  2035. +
  2036. +#include <linux/kernel.h>
  2037. +#include <linux/limits.h>
  2038. +#include <linux/module.h>
  2039. +#include <linux/types.h>
  2040. +#include <linux/workqueue.h>
  2041. +
  2042. +#include <linux/surface_aggregator/device.h>
  2043. +
  2044. +
  2045. +/* -- SSAM generic subsystem hub driver framework. -------------------------- */
  2046. +
  2047. +enum ssam_hub_state {
  2048. + SSAM_HUB_UNINITIALIZED, /* Only set during initialization. */
  2049. + SSAM_HUB_CONNECTED,
  2050. + SSAM_HUB_DISCONNECTED,
  2051. +};
  2052. +
  2053. +enum ssam_hub_flags {
  2054. + SSAM_HUB_HOT_REMOVED,
  2055. +};
  2056. +
  2057. +struct ssam_hub {
  2058. + struct ssam_device *sdev;
  2059. +
  2060. + enum ssam_hub_state state;
  2061. + unsigned long flags;
  2062. +
  2063. + struct delayed_work update_work;
  2064. + unsigned long connect_delay;
  2065. +
  2066. + struct ssam_event_notifier notif;
  2067. +
  2068. + int (*get_state)(struct ssam_hub *hub, enum ssam_hub_state *state);
  2069. +};
  2070. +
  2071. +struct ssam_hub_info {
  2072. + struct {
  2073. + struct ssam_event_registry reg;
  2074. + struct ssam_event_id id;
  2075. + enum ssam_event_mask mask;
  2076. + u8 flags;
  2077. + } event;
  2078. +
  2079. + u32 (*notify)(struct ssam_event_notifier *nf, const struct ssam_event *event);
  2080. + int (*get_state)(struct ssam_hub *hub, enum ssam_hub_state *state);
  2081. +
  2082. + unsigned long connect_delay_ms;
  2083. +};
  2084. +
  2085. +static void ssam_hub_update_workfn(struct work_struct *work)
  2086. +{
  2087. + struct ssam_hub *hub = container_of(work, struct ssam_hub, update_work.work);
  2088. + enum ssam_hub_state state;
  2089. + int status = 0;
  2090. +
  2091. + status = hub->get_state(hub, &state);
  2092. + if (status)
  2093. + return;
  2094. +
  2095. + /*
  2096. + * There is a small possibility that hub devices were hot-removed and
  2097. + * re-added before we were able to remove them here. In that case, both
  2098. + * the state returned by get_state() and the state of the hub will
  2099. + * equal SSAM_HUB_CONNECTED and we would bail early below, which would
  2100. + * leave child devices without proper (re-)initialization and the
  2101. + * hot-remove flag set.
  2102. + *
  2103. + * Therefore, we check whether devices have been hot-removed via an
  2104. + * additional flag on the hub and, in this case, override the returned
  2105. + * hub state. In case of a missed disconnect (i.e. get_state returned
  2106. + * "connected"), we further need to re-schedule this work (with the
  2107. + * appropriate delay) as the actual connect work submission might have
  2108. + * been merged with this one.
  2109. + *
  2110. + * This then leads to one of two cases: Either we submit an unnecessary
  2111. + * work item (which will get ignored via either the queue or the state
  2112. + * checks) or, in the unlikely case that the work is actually required,
  2113. + * double the normal connect delay.
  2114. + */
  2115. + if (test_and_clear_bit(SSAM_HUB_HOT_REMOVED, &hub->flags)) {
  2116. + if (state == SSAM_HUB_CONNECTED)
  2117. + schedule_delayed_work(&hub->update_work, hub->connect_delay);
  2118. +
  2119. + state = SSAM_HUB_DISCONNECTED;
  2120. + }
  2121. +
  2122. + if (hub->state == state)
  2123. + return;
  2124. + hub->state = state;
  2125. +
  2126. + if (hub->state == SSAM_HUB_CONNECTED)
  2127. + status = ssam_device_register_clients(hub->sdev);
  2128. + else
  2129. + ssam_remove_clients(&hub->sdev->dev);
  2130. +
  2131. + if (status)
  2132. + dev_err(&hub->sdev->dev, "failed to update hub child devices: %d\n", status);
  2133. +}
  2134. +
  2135. +static int ssam_hub_mark_hot_removed(struct device *dev, void *_data)
  2136. +{
  2137. + struct ssam_device *sdev = to_ssam_device(dev);
  2138. +
  2139. + if (is_ssam_device(dev))
  2140. + ssam_device_mark_hot_removed(sdev);
  2141. +
  2142. + return 0;
  2143. +}
  2144. +
  2145. +static void ssam_hub_update(struct ssam_hub *hub, bool connected)
  2146. +{
  2147. + unsigned long delay;
  2148. +
  2149. + /* Mark devices as hot-removed before we remove any. */
  2150. + if (!connected) {
  2151. + set_bit(SSAM_HUB_HOT_REMOVED, &hub->flags);
  2152. + device_for_each_child_reverse(&hub->sdev->dev, NULL, ssam_hub_mark_hot_removed);
  2153. + }
  2154. +
  2155. + /*
  2156. + * Delay update when the base/keyboard cover is being connected to give
  2157. + * devices/EC some time to set up.
  2158. + */
  2159. + delay = connected ? hub->connect_delay : 0;
  2160. +
  2161. + schedule_delayed_work(&hub->update_work, delay);
  2162. +}
  2163. +
  2164. +static int __maybe_unused ssam_hub_resume(struct device *dev)
  2165. +{
  2166. + struct ssam_hub *hub = dev_get_drvdata(dev);
  2167. +
  2168. + schedule_delayed_work(&hub->update_work, 0);
  2169. + return 0;
  2170. +}
  2171. +static SIMPLE_DEV_PM_OPS(ssam_hub_pm_ops, NULL, ssam_hub_resume);
  2172. +
  2173. +static int ssam_hub_probe(struct ssam_device *sdev)
  2174. +{
  2175. + const struct ssam_hub_info *info;
  2176. + struct ssam_hub *hub;
  2177. + int status;
  2178. +
  2179. + info = ssam_device_get_match_data(sdev);
  2180. + if (!info) {
  2181. + WARN(1, "no driver match data specified");
  2182. + return -EINVAL;
  2183. + }
  2184. +
  2185. + hub = devm_kzalloc(&sdev->dev, sizeof(*hub), GFP_KERNEL);
  2186. + if (!hub)
  2187. + return -ENOMEM;
  2188. +
  2189. + hub->sdev = sdev;
  2190. + hub->state = SSAM_HUB_UNINITIALIZED;
  2191. +
  2192. + hub->notif.base.priority = INT_MAX; /* This notifier should run first. */
  2193. + hub->notif.base.fn = info->notify;
  2194. + hub->notif.event.reg = info->event.reg;
  2195. + hub->notif.event.id = info->event.id;
  2196. + hub->notif.event.mask = info->event.mask;
  2197. + hub->notif.event.flags = info->event.flags;
  2198. +
  2199. + hub->connect_delay = msecs_to_jiffies(info->connect_delay_ms);
  2200. + hub->get_state = info->get_state;
  2201. +
  2202. + INIT_DELAYED_WORK(&hub->update_work, ssam_hub_update_workfn);
  2203. +
  2204. + ssam_device_set_drvdata(sdev, hub);
  2205. +
  2206. + status = ssam_device_notifier_register(sdev, &hub->notif);
  2207. + if (status)
  2208. + return status;
  2209. +
  2210. + schedule_delayed_work(&hub->update_work, 0);
  2211. + return 0;
  2212. +}
  2213. +
  2214. +static void ssam_hub_remove(struct ssam_device *sdev)
  2215. +{
  2216. + struct ssam_hub *hub = ssam_device_get_drvdata(sdev);
  2217. +
  2218. + ssam_device_notifier_unregister(sdev, &hub->notif);
  2219. + cancel_delayed_work_sync(&hub->update_work);
  2220. + ssam_remove_clients(&sdev->dev);
  2221. +}
  2222. +
  2223. +
  2224. +/* -- SSAM base-subsystem hub driver. --------------------------------------- */
  2225. +
  2226. +/*
  2227. + * Some devices (especially battery) may need a bit of time to be fully usable
  2228. + * after being (re-)connected. This delay has been determined via
  2229. + * experimentation.
  2230. + */
  2231. +#define SSAM_BASE_UPDATE_CONNECT_DELAY 2500
  2232. +
  2233. +SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_query_opmode, u8, {
  2234. + .target_category = SSAM_SSH_TC_BAS,
  2235. + .target_id = 0x01,
  2236. + .command_id = 0x0d,
  2237. + .instance_id = 0x00,
  2238. +});
  2239. +
  2240. +#define SSAM_BAS_OPMODE_TABLET 0x00
  2241. +#define SSAM_EVENT_BAS_CID_CONNECTION 0x0c
  2242. +
  2243. +static int ssam_base_hub_query_state(struct ssam_hub *hub, enum ssam_hub_state *state)
  2244. +{
  2245. + u8 opmode;
  2246. + int status;
  2247. +
  2248. + status = ssam_retry(ssam_bas_query_opmode, hub->sdev->ctrl, &opmode);
  2249. + if (status < 0) {
  2250. + dev_err(&hub->sdev->dev, "failed to query base state: %d\n", status);
  2251. + return status;
  2252. + }
  2253. +
  2254. + if (opmode != SSAM_BAS_OPMODE_TABLET)
  2255. + *state = SSAM_HUB_CONNECTED;
  2256. + else
  2257. + *state = SSAM_HUB_DISCONNECTED;
  2258. +
  2259. + return 0;
  2260. +}
  2261. +
  2262. +static u32 ssam_base_hub_notif(struct ssam_event_notifier *nf, const struct ssam_event *event)
  2263. +{
  2264. + struct ssam_hub *hub = container_of(nf, struct ssam_hub, notif);
  2265. +
  2266. + if (event->command_id != SSAM_EVENT_BAS_CID_CONNECTION)
  2267. + return 0;
  2268. +
  2269. + if (event->length < 1) {
  2270. + dev_err(&hub->sdev->dev, "unexpected payload size: %u\n", event->length);
  2271. + return 0;
  2272. + }
  2273. +
  2274. + ssam_hub_update(hub, event->data[0]);
  2275. +
  2276. + /*
  2277. + * Do not return SSAM_NOTIF_HANDLED: The event should be picked up and
  2278. + * consumed by the detachment system driver. We're just a (more or less)
  2279. + * silent observer.
  2280. + */
  2281. + return 0;
  2282. +}
  2283. +
  2284. +static const struct ssam_hub_info base_hub = {
  2285. + .event = {
  2286. + .reg = SSAM_EVENT_REGISTRY_SAM,
  2287. + .id = {
  2288. + .target_category = SSAM_SSH_TC_BAS,
  2289. + .instance = 0,
  2290. + },
  2291. + .mask = SSAM_EVENT_MASK_NONE,
  2292. + .flags = SSAM_EVENT_SEQUENCED,
  2293. + },
  2294. + .notify = ssam_base_hub_notif,
  2295. + .get_state = ssam_base_hub_query_state,
  2296. + .connect_delay_ms = SSAM_BASE_UPDATE_CONNECT_DELAY,
  2297. +};
  2298. +
  2299. +
  2300. +/* -- SSAM KIP-subsystem hub driver. ---------------------------------------- */
  2301. +
  2302. +/*
  2303. + * Some devices may need a bit of time to be fully usable after being
  2304. + * (re-)connected. This delay has been determined via experimentation.
  2305. + */
  2306. +#define SSAM_KIP_UPDATE_CONNECT_DELAY 250
  2307. +
  2308. +#define SSAM_EVENT_KIP_CID_CONNECTION 0x2c
  2309. +
  2310. +SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_query_state, u8, {
  2311. + .target_category = SSAM_SSH_TC_KIP,
  2312. + .target_id = 0x01,
  2313. + .command_id = 0x2c,
  2314. + .instance_id = 0x00,
  2315. +});
  2316. +
  2317. +static int ssam_kip_hub_query_state(struct ssam_hub *hub, enum ssam_hub_state *state)
  2318. +{
  2319. + int status;
  2320. + u8 connected;
  2321. +
  2322. + status = ssam_retry(__ssam_kip_query_state, hub->sdev->ctrl, &connected);
  2323. + if (status < 0) {
  2324. + dev_err(&hub->sdev->dev, "failed to query KIP connection state: %d\n", status);
  2325. + return status;
  2326. + }
  2327. +
  2328. + *state = connected ? SSAM_HUB_CONNECTED : SSAM_HUB_DISCONNECTED;
  2329. + return 0;
  2330. +}
  2331. +
  2332. +static u32 ssam_kip_hub_notif(struct ssam_event_notifier *nf, const struct ssam_event *event)
  2333. +{
  2334. + struct ssam_hub *hub = container_of(nf, struct ssam_hub, notif);
  2335. +
  2336. + if (event->command_id != SSAM_EVENT_KIP_CID_CONNECTION)
  2337. + return 0; /* Return "unhandled". */
  2338. +
  2339. + if (event->length < 1) {
  2340. + dev_err(&hub->sdev->dev, "unexpected payload size: %u\n", event->length);
  2341. + return 0;
  2342. + }
  2343. +
  2344. + ssam_hub_update(hub, event->data[0]);
  2345. + return SSAM_NOTIF_HANDLED;
  2346. +}
  2347. +
  2348. +static const struct ssam_hub_info kip_hub = {
  2349. + .event = {
  2350. + .reg = SSAM_EVENT_REGISTRY_SAM,
  2351. + .id = {
  2352. + .target_category = SSAM_SSH_TC_KIP,
  2353. + .instance = 0,
  2354. + },
  2355. + .mask = SSAM_EVENT_MASK_TARGET,
  2356. + .flags = SSAM_EVENT_SEQUENCED,
  2357. + },
  2358. + .notify = ssam_kip_hub_notif,
  2359. + .get_state = ssam_kip_hub_query_state,
  2360. + .connect_delay_ms = SSAM_KIP_UPDATE_CONNECT_DELAY,
  2361. +};
  2362. +
  2363. +
  2364. +/* -- Driver registration. -------------------------------------------------- */
  2365. +
  2366. +static const struct ssam_device_id ssam_hub_match[] = {
  2367. + { SSAM_VDEV(HUB, 0x02, SSAM_ANY_IID, 0x00), (unsigned long)&base_hub },
  2368. + { SSAM_SDEV(KIP, 0x01, 0x00, 0x00), (unsigned long)&kip_hub },
  2369. + { }
  2370. +};
  2371. +MODULE_DEVICE_TABLE(ssam, ssam_hub_match);
  2372. +
  2373. +static struct ssam_device_driver ssam_subsystem_hub_driver = {
  2374. + .probe = ssam_hub_probe,
  2375. + .remove = ssam_hub_remove,
  2376. + .match_table = ssam_hub_match,
  2377. + .driver = {
  2378. + .name = "surface_aggregator_subsystem_hub",
  2379. + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  2380. + .pm = &ssam_hub_pm_ops,
  2381. + },
  2382. +};
  2383. +module_ssam_device_driver(ssam_subsystem_hub_driver);
  2384. +
  2385. +MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
  2386. +MODULE_DESCRIPTION("Subsystem device hub driver for Surface System Aggregator Module");
  2387. +MODULE_LICENSE("GPL");
  2388. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  2389. index 3261c8141841..11b51aa9ea73 100644
  2390. --- a/drivers/platform/surface/surface_aggregator_registry.c
  2391. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  2392. @@ -11,14 +11,11 @@
  2393. #include <linux/acpi.h>
  2394. #include <linux/kernel.h>
  2395. -#include <linux/limits.h>
  2396. #include <linux/module.h>
  2397. #include <linux/platform_device.h>
  2398. #include <linux/property.h>
  2399. #include <linux/types.h>
  2400. -#include <linux/workqueue.h>
  2401. -#include <linux/surface_aggregator/controller.h>
  2402. #include <linux/surface_aggregator/device.h>
  2403. @@ -279,335 +276,6 @@ static const struct software_node *ssam_node_group_sp8[] = {
  2404. };
  2405. -/* -- SSAM generic subsystem hub driver framework. -------------------------- */
  2406. -
  2407. -enum ssam_hub_state {
  2408. - SSAM_HUB_UNINITIALIZED, /* Only set during initialization. */
  2409. - SSAM_HUB_CONNECTED,
  2410. - SSAM_HUB_DISCONNECTED,
  2411. -};
  2412. -
  2413. -enum ssam_hub_flags {
  2414. - SSAM_HUB_HOT_REMOVED,
  2415. -};
  2416. -
  2417. -struct ssam_hub {
  2418. - struct ssam_device *sdev;
  2419. -
  2420. - enum ssam_hub_state state;
  2421. - unsigned long flags;
  2422. -
  2423. - struct delayed_work update_work;
  2424. - unsigned long connect_delay;
  2425. -
  2426. - struct ssam_event_notifier notif;
  2427. -
  2428. - int (*get_state)(struct ssam_hub *hub, enum ssam_hub_state *state);
  2429. -};
  2430. -
  2431. -static void ssam_hub_update_workfn(struct work_struct *work)
  2432. -{
  2433. - struct ssam_hub *hub = container_of(work, struct ssam_hub, update_work.work);
  2434. - enum ssam_hub_state state;
  2435. - int status = 0;
  2436. -
  2437. - status = hub->get_state(hub, &state);
  2438. - if (status)
  2439. - return;
  2440. -
  2441. - /*
  2442. - * There is a small possibility that hub devices were hot-removed and
  2443. - * re-added before we were able to remove them here. In that case, both
  2444. - * the state returned by get_state() and the state of the hub will
  2445. - * equal SSAM_HUB_CONNECTED and we would bail early below, which would
  2446. - * leave child devices without proper (re-)initialization and the
  2447. - * hot-remove flag set.
  2448. - *
  2449. - * Therefore, we check whether devices have been hot-removed via an
  2450. - * additional flag on the hub and, in this case, override the returned
  2451. - * hub state. In case of a missed disconnect (i.e. get_state returned
  2452. - * "connected"), we further need to re-schedule this work (with the
  2453. - * appropriate delay) as the actual connect work submission might have
  2454. - * been merged with this one.
  2455. - *
  2456. - * This then leads to one of two cases: Either we submit an unnecessary
  2457. - * work item (which will get ignored via either the queue or the state
  2458. - * checks) or, in the unlikely case that the work is actually required,
  2459. - * double the normal connect delay.
  2460. - */
  2461. - if (test_and_clear_bit(SSAM_HUB_HOT_REMOVED, &hub->flags)) {
  2462. - if (state == SSAM_HUB_CONNECTED)
  2463. - schedule_delayed_work(&hub->update_work, hub->connect_delay);
  2464. -
  2465. - state = SSAM_HUB_DISCONNECTED;
  2466. - }
  2467. -
  2468. - if (hub->state == state)
  2469. - return;
  2470. - hub->state = state;
  2471. -
  2472. - if (hub->state == SSAM_HUB_CONNECTED)
  2473. - status = ssam_device_register_clients(hub->sdev);
  2474. - else
  2475. - ssam_remove_clients(&hub->sdev->dev);
  2476. -
  2477. - if (status)
  2478. - dev_err(&hub->sdev->dev, "failed to update hub child devices: %d\n", status);
  2479. -}
  2480. -
  2481. -static int ssam_hub_mark_hot_removed(struct device *dev, void *_data)
  2482. -{
  2483. - struct ssam_device *sdev = to_ssam_device(dev);
  2484. -
  2485. - if (is_ssam_device(dev))
  2486. - ssam_device_mark_hot_removed(sdev);
  2487. -
  2488. - return 0;
  2489. -}
  2490. -
  2491. -static void ssam_hub_update(struct ssam_hub *hub, bool connected)
  2492. -{
  2493. - unsigned long delay;
  2494. -
  2495. - /* Mark devices as hot-removed before we remove any. */
  2496. - if (!connected) {
  2497. - set_bit(SSAM_HUB_HOT_REMOVED, &hub->flags);
  2498. - device_for_each_child_reverse(&hub->sdev->dev, NULL, ssam_hub_mark_hot_removed);
  2499. - }
  2500. -
  2501. - /*
  2502. - * Delay update when the base/keyboard cover is being connected to give
  2503. - * devices/EC some time to set up.
  2504. - */
  2505. - delay = connected ? hub->connect_delay : 0;
  2506. -
  2507. - schedule_delayed_work(&hub->update_work, delay);
  2508. -}
  2509. -
  2510. -static int __maybe_unused ssam_hub_resume(struct device *dev)
  2511. -{
  2512. - struct ssam_hub *hub = dev_get_drvdata(dev);
  2513. -
  2514. - schedule_delayed_work(&hub->update_work, 0);
  2515. - return 0;
  2516. -}
  2517. -static SIMPLE_DEV_PM_OPS(ssam_hub_pm_ops, NULL, ssam_hub_resume);
  2518. -
  2519. -static int ssam_hub_setup(struct ssam_device *sdev, struct ssam_hub *hub)
  2520. -{
  2521. - int status;
  2522. -
  2523. - hub->sdev = sdev;
  2524. - hub->state = SSAM_HUB_UNINITIALIZED;
  2525. -
  2526. - INIT_DELAYED_WORK(&hub->update_work, ssam_hub_update_workfn);
  2527. -
  2528. - ssam_device_set_drvdata(sdev, hub);
  2529. -
  2530. - status = ssam_device_notifier_register(sdev, &hub->notif);
  2531. - if (status)
  2532. - return status;
  2533. -
  2534. - schedule_delayed_work(&hub->update_work, 0);
  2535. - return 0;
  2536. -}
  2537. -
  2538. -static void ssam_hub_remove(struct ssam_device *sdev)
  2539. -{
  2540. - struct ssam_hub *hub = ssam_device_get_drvdata(sdev);
  2541. -
  2542. - ssam_device_notifier_unregister(sdev, &hub->notif);
  2543. - cancel_delayed_work_sync(&hub->update_work);
  2544. - ssam_remove_clients(&sdev->dev);
  2545. -}
  2546. -
  2547. -
  2548. -/* -- SSAM base-hub driver. ------------------------------------------------- */
  2549. -
  2550. -/*
  2551. - * Some devices (especially battery) may need a bit of time to be fully usable
  2552. - * after being (re-)connected. This delay has been determined via
  2553. - * experimentation.
  2554. - */
  2555. -#define SSAM_BASE_UPDATE_CONNECT_DELAY msecs_to_jiffies(2500)
  2556. -
  2557. -SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_query_opmode, u8, {
  2558. - .target_category = SSAM_SSH_TC_BAS,
  2559. - .target_id = 0x01,
  2560. - .command_id = 0x0d,
  2561. - .instance_id = 0x00,
  2562. -});
  2563. -
  2564. -#define SSAM_BAS_OPMODE_TABLET 0x00
  2565. -#define SSAM_EVENT_BAS_CID_CONNECTION 0x0c
  2566. -
  2567. -static int ssam_base_hub_query_state(struct ssam_hub *hub, enum ssam_hub_state *state)
  2568. -{
  2569. - u8 opmode;
  2570. - int status;
  2571. -
  2572. - status = ssam_retry(ssam_bas_query_opmode, hub->sdev->ctrl, &opmode);
  2573. - if (status < 0) {
  2574. - dev_err(&hub->sdev->dev, "failed to query base state: %d\n", status);
  2575. - return status;
  2576. - }
  2577. -
  2578. - if (opmode != SSAM_BAS_OPMODE_TABLET)
  2579. - *state = SSAM_HUB_CONNECTED;
  2580. - else
  2581. - *state = SSAM_HUB_DISCONNECTED;
  2582. -
  2583. - return 0;
  2584. -}
  2585. -
  2586. -static u32 ssam_base_hub_notif(struct ssam_event_notifier *nf, const struct ssam_event *event)
  2587. -{
  2588. - struct ssam_hub *hub = container_of(nf, struct ssam_hub, notif);
  2589. -
  2590. - if (event->command_id != SSAM_EVENT_BAS_CID_CONNECTION)
  2591. - return 0;
  2592. -
  2593. - if (event->length < 1) {
  2594. - dev_err(&hub->sdev->dev, "unexpected payload size: %u\n", event->length);
  2595. - return 0;
  2596. - }
  2597. -
  2598. - ssam_hub_update(hub, event->data[0]);
  2599. -
  2600. - /*
  2601. - * Do not return SSAM_NOTIF_HANDLED: The event should be picked up and
  2602. - * consumed by the detachment system driver. We're just a (more or less)
  2603. - * silent observer.
  2604. - */
  2605. - return 0;
  2606. -}
  2607. -
  2608. -static int ssam_base_hub_probe(struct ssam_device *sdev)
  2609. -{
  2610. - struct ssam_hub *hub;
  2611. -
  2612. - hub = devm_kzalloc(&sdev->dev, sizeof(*hub), GFP_KERNEL);
  2613. - if (!hub)
  2614. - return -ENOMEM;
  2615. -
  2616. - hub->notif.base.priority = INT_MAX; /* This notifier should run first. */
  2617. - hub->notif.base.fn = ssam_base_hub_notif;
  2618. - hub->notif.event.reg = SSAM_EVENT_REGISTRY_SAM;
  2619. - hub->notif.event.id.target_category = SSAM_SSH_TC_BAS,
  2620. - hub->notif.event.id.instance = 0,
  2621. - hub->notif.event.mask = SSAM_EVENT_MASK_NONE;
  2622. - hub->notif.event.flags = SSAM_EVENT_SEQUENCED;
  2623. -
  2624. - hub->connect_delay = SSAM_BASE_UPDATE_CONNECT_DELAY;
  2625. - hub->get_state = ssam_base_hub_query_state;
  2626. -
  2627. - return ssam_hub_setup(sdev, hub);
  2628. -}
  2629. -
  2630. -static const struct ssam_device_id ssam_base_hub_match[] = {
  2631. - { SSAM_VDEV(HUB, 0x02, SSAM_ANY_IID, 0x00) },
  2632. - { },
  2633. -};
  2634. -
  2635. -static struct ssam_device_driver ssam_base_hub_driver = {
  2636. - .probe = ssam_base_hub_probe,
  2637. - .remove = ssam_hub_remove,
  2638. - .match_table = ssam_base_hub_match,
  2639. - .driver = {
  2640. - .name = "surface_aggregator_base_hub",
  2641. - .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  2642. - .pm = &ssam_hub_pm_ops,
  2643. - },
  2644. -};
  2645. -
  2646. -
  2647. -/* -- SSAM KIP-subsystem hub driver. ---------------------------------------- */
  2648. -
  2649. -/*
  2650. - * Some devices may need a bit of time to be fully usable after being
  2651. - * (re-)connected. This delay has been determined via experimentation.
  2652. - */
  2653. -#define SSAM_KIP_UPDATE_CONNECT_DELAY msecs_to_jiffies(250)
  2654. -
  2655. -#define SSAM_EVENT_KIP_CID_CONNECTION 0x2c
  2656. -
  2657. -SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_get_connection_state, u8, {
  2658. - .target_category = SSAM_SSH_TC_KIP,
  2659. - .target_id = 0x01,
  2660. - .command_id = 0x2c,
  2661. - .instance_id = 0x00,
  2662. -});
  2663. -
  2664. -static int ssam_kip_get_connection_state(struct ssam_hub *hub, enum ssam_hub_state *state)
  2665. -{
  2666. - int status;
  2667. - u8 connected;
  2668. -
  2669. - status = ssam_retry(__ssam_kip_get_connection_state, hub->sdev->ctrl, &connected);
  2670. - if (status < 0) {
  2671. - dev_err(&hub->sdev->dev, "failed to query KIP connection state: %d\n", status);
  2672. - return status;
  2673. - }
  2674. -
  2675. - *state = connected ? SSAM_HUB_CONNECTED : SSAM_HUB_DISCONNECTED;
  2676. - return 0;
  2677. -}
  2678. -
  2679. -static u32 ssam_kip_hub_notif(struct ssam_event_notifier *nf, const struct ssam_event *event)
  2680. -{
  2681. - struct ssam_hub *hub = container_of(nf, struct ssam_hub, notif);
  2682. -
  2683. - if (event->command_id != SSAM_EVENT_KIP_CID_CONNECTION)
  2684. - return 0; /* Return "unhandled". */
  2685. -
  2686. - if (event->length < 1) {
  2687. - dev_err(&hub->sdev->dev, "unexpected payload size: %u\n", event->length);
  2688. - return 0;
  2689. - }
  2690. -
  2691. - ssam_hub_update(hub, event->data[0]);
  2692. - return SSAM_NOTIF_HANDLED;
  2693. -}
  2694. -
  2695. -static int ssam_kip_hub_probe(struct ssam_device *sdev)
  2696. -{
  2697. - struct ssam_hub *hub;
  2698. -
  2699. - hub = devm_kzalloc(&sdev->dev, sizeof(*hub), GFP_KERNEL);
  2700. - if (!hub)
  2701. - return -ENOMEM;
  2702. -
  2703. - hub->notif.base.priority = INT_MAX; /* This notifier should run first. */
  2704. - hub->notif.base.fn = ssam_kip_hub_notif;
  2705. - hub->notif.event.reg = SSAM_EVENT_REGISTRY_SAM;
  2706. - hub->notif.event.id.target_category = SSAM_SSH_TC_KIP,
  2707. - hub->notif.event.id.instance = 0,
  2708. - hub->notif.event.mask = SSAM_EVENT_MASK_TARGET;
  2709. - hub->notif.event.flags = SSAM_EVENT_SEQUENCED;
  2710. -
  2711. - hub->connect_delay = SSAM_KIP_UPDATE_CONNECT_DELAY;
  2712. - hub->get_state = ssam_kip_get_connection_state;
  2713. -
  2714. - return ssam_hub_setup(sdev, hub);
  2715. -}
  2716. -
  2717. -static const struct ssam_device_id ssam_kip_hub_match[] = {
  2718. - { SSAM_SDEV(KIP, 0x01, 0x00, 0x00) },
  2719. - { },
  2720. -};
  2721. -
  2722. -static struct ssam_device_driver ssam_kip_hub_driver = {
  2723. - .probe = ssam_kip_hub_probe,
  2724. - .remove = ssam_hub_remove,
  2725. - .match_table = ssam_kip_hub_match,
  2726. - .driver = {
  2727. - .name = "surface_kip_hub",
  2728. - .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  2729. - .pm = &ssam_hub_pm_ops,
  2730. - },
  2731. -};
  2732. -
  2733. -
  2734. /* -- SSAM platform/meta-hub driver. ---------------------------------------- */
  2735. static const struct acpi_device_id ssam_platform_hub_match[] = {
  2736. @@ -720,44 +388,7 @@ static struct platform_driver ssam_platform_hub_driver = {
  2737. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  2738. },
  2739. };
  2740. -
  2741. -
  2742. -/* -- Module initialization. ------------------------------------------------ */
  2743. -
  2744. -static int __init ssam_device_hub_init(void)
  2745. -{
  2746. - int status;
  2747. -
  2748. - status = platform_driver_register(&ssam_platform_hub_driver);
  2749. - if (status)
  2750. - goto err_platform;
  2751. -
  2752. - status = ssam_device_driver_register(&ssam_base_hub_driver);
  2753. - if (status)
  2754. - goto err_base;
  2755. -
  2756. - status = ssam_device_driver_register(&ssam_kip_hub_driver);
  2757. - if (status)
  2758. - goto err_kip;
  2759. -
  2760. - return 0;
  2761. -
  2762. -err_kip:
  2763. - ssam_device_driver_unregister(&ssam_base_hub_driver);
  2764. -err_base:
  2765. - platform_driver_unregister(&ssam_platform_hub_driver);
  2766. -err_platform:
  2767. - return status;
  2768. -}
  2769. -module_init(ssam_device_hub_init);
  2770. -
  2771. -static void __exit ssam_device_hub_exit(void)
  2772. -{
  2773. - ssam_device_driver_unregister(&ssam_kip_hub_driver);
  2774. - ssam_device_driver_unregister(&ssam_base_hub_driver);
  2775. - platform_driver_unregister(&ssam_platform_hub_driver);
  2776. -}
  2777. -module_exit(ssam_device_hub_exit);
  2778. +module_platform_driver(ssam_platform_hub_driver);
  2779. MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
  2780. MODULE_DESCRIPTION("Device-registry for Surface System Aggregator Module");
  2781. --
  2782. 2.36.1
  2783. From 7b3b163901724689e4c52468232552f38d503523 Mon Sep 17 00:00:00 2001
  2784. From: Maximilian Luz <luzmaximilian@gmail.com>
  2785. Date: Sat, 21 May 2022 00:51:05 +0200
  2786. Subject: [PATCH] platform/surface: aggregator: Be consistent with hub device
  2787. IDs
  2788. Currently, we use a virtual device ID for the base (BAS) hub but an
  2789. actual device ID for the KIP hub. Let's be consistent about the naming
  2790. format and make all hubs virtual, with their instance ID reflecting the
  2791. subsystem.
  2792. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  2793. Patchset: surface-sam
  2794. ---
  2795. drivers/platform/surface/surface_aggregator_hub.c | 4 ++--
  2796. .../platform/surface/surface_aggregator_registry.c | 12 ++++++------
  2797. 2 files changed, 8 insertions(+), 8 deletions(-)
  2798. diff --git a/drivers/platform/surface/surface_aggregator_hub.c b/drivers/platform/surface/surface_aggregator_hub.c
  2799. index 20b1c38debfe..c473bdebf90c 100644
  2800. --- a/drivers/platform/surface/surface_aggregator_hub.c
  2801. +++ b/drivers/platform/surface/surface_aggregator_hub.c
  2802. @@ -340,8 +340,8 @@ static const struct ssam_hub_info kip_hub = {
  2803. /* -- Driver registration. -------------------------------------------------- */
  2804. static const struct ssam_device_id ssam_hub_match[] = {
  2805. - { SSAM_VDEV(HUB, 0x02, SSAM_ANY_IID, 0x00), (unsigned long)&base_hub },
  2806. - { SSAM_SDEV(KIP, 0x01, 0x00, 0x00), (unsigned long)&kip_hub },
  2807. + { SSAM_VDEV(HUB, 0x01, SSAM_SSH_TC_KIP, 0x00), (unsigned long)&kip_hub },
  2808. + { SSAM_VDEV(HUB, 0x02, SSAM_SSH_TC_BAS, 0x00), (unsigned long)&base_hub },
  2809. { }
  2810. };
  2811. MODULE_DEVICE_TABLE(ssam, ssam_hub_match);
  2812. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  2813. index 11b51aa9ea73..cee7121e7fa6 100644
  2814. --- a/drivers/platform/surface/surface_aggregator_registry.c
  2815. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  2816. @@ -38,15 +38,15 @@ static const struct software_node ssam_node_root = {
  2817. .name = "ssam_platform_hub",
  2818. };
  2819. -/* Base device hub (devices attached to Surface Book 3 base). */
  2820. -static const struct software_node ssam_node_hub_base = {
  2821. - .name = "ssam:00:00:02:00:00",
  2822. +/* KIP device hub (connects keyboard cover devices on Surface Pro 8). */
  2823. +static const struct software_node ssam_node_hub_kip = {
  2824. + .name = "ssam:00:00:01:0e:00",
  2825. .parent = &ssam_node_root,
  2826. };
  2827. -/* KIP device hub (connects keyboard cover devices on Surface Pro 8). */
  2828. -static const struct software_node ssam_node_hub_kip = {
  2829. - .name = "ssam:01:0e:01:00:00",
  2830. +/* Base device hub (devices attached to Surface Book 3 base). */
  2831. +static const struct software_node ssam_node_hub_base = {
  2832. + .name = "ssam:00:00:02:11:00",
  2833. .parent = &ssam_node_root,
  2834. };
  2835. --
  2836. 2.36.1
  2837. From da96ae977277e2c11ebbaf7755bc08b6e611bac3 Mon Sep 17 00:00:00 2001
  2838. From: Maximilian Luz <luzmaximilian@gmail.com>
  2839. Date: Sat, 21 May 2022 00:57:40 +0200
  2840. Subject: [PATCH] platform/surface: Update copyright year of various drivers
  2841. Update the copyright of various Surface drivers to the current year.
  2842. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  2843. Patchset: surface-sam
  2844. ---
  2845. drivers/platform/surface/aggregator/Kconfig | 2 +-
  2846. drivers/platform/surface/aggregator/Makefile | 2 +-
  2847. drivers/platform/surface/aggregator/bus.c | 2 +-
  2848. drivers/platform/surface/aggregator/bus.h | 2 +-
  2849. drivers/platform/surface/aggregator/controller.c | 2 +-
  2850. drivers/platform/surface/aggregator/controller.h | 2 +-
  2851. drivers/platform/surface/aggregator/core.c | 2 +-
  2852. drivers/platform/surface/aggregator/ssh_msgb.h | 2 +-
  2853. drivers/platform/surface/aggregator/ssh_packet_layer.c | 2 +-
  2854. drivers/platform/surface/aggregator/ssh_packet_layer.h | 2 +-
  2855. drivers/platform/surface/aggregator/ssh_parser.c | 2 +-
  2856. drivers/platform/surface/aggregator/ssh_parser.h | 2 +-
  2857. drivers/platform/surface/aggregator/ssh_request_layer.c | 2 +-
  2858. drivers/platform/surface/aggregator/ssh_request_layer.h | 2 +-
  2859. drivers/platform/surface/aggregator/trace.h | 2 +-
  2860. drivers/platform/surface/surface_acpi_notify.c | 2 +-
  2861. drivers/platform/surface/surface_aggregator_cdev.c | 2 +-
  2862. drivers/platform/surface/surface_aggregator_registry.c | 2 +-
  2863. drivers/platform/surface/surface_dtx.c | 2 +-
  2864. drivers/platform/surface/surface_gpe.c | 2 +-
  2865. drivers/platform/surface/surface_hotplug.c | 2 +-
  2866. drivers/platform/surface/surface_platform_profile.c | 2 +-
  2867. 22 files changed, 22 insertions(+), 22 deletions(-)
  2868. diff --git a/drivers/platform/surface/aggregator/Kconfig b/drivers/platform/surface/aggregator/Kconfig
  2869. index cab020324256..c114f9dd5fe1 100644
  2870. --- a/drivers/platform/surface/aggregator/Kconfig
  2871. +++ b/drivers/platform/surface/aggregator/Kconfig
  2872. @@ -1,5 +1,5 @@
  2873. # SPDX-License-Identifier: GPL-2.0+
  2874. -# Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2875. +# Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2876. menuconfig SURFACE_AGGREGATOR
  2877. tristate "Microsoft Surface System Aggregator Module Subsystem and Drivers"
  2878. diff --git a/drivers/platform/surface/aggregator/Makefile b/drivers/platform/surface/aggregator/Makefile
  2879. index c0d550eda5cd..fdf664a217f9 100644
  2880. --- a/drivers/platform/surface/aggregator/Makefile
  2881. +++ b/drivers/platform/surface/aggregator/Makefile
  2882. @@ -1,5 +1,5 @@
  2883. # SPDX-License-Identifier: GPL-2.0+
  2884. -# Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2885. +# Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2886. # For include/trace/define_trace.h to include trace.h
  2887. CFLAGS_core.o = -I$(src)
  2888. diff --git a/drivers/platform/surface/aggregator/bus.c b/drivers/platform/surface/aggregator/bus.c
  2889. index 4bba60884bb5..96986042a257 100644
  2890. --- a/drivers/platform/surface/aggregator/bus.c
  2891. +++ b/drivers/platform/surface/aggregator/bus.c
  2892. @@ -2,7 +2,7 @@
  2893. /*
  2894. * Surface System Aggregator Module bus and device integration.
  2895. *
  2896. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2897. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2898. */
  2899. #include <linux/device.h>
  2900. diff --git a/drivers/platform/surface/aggregator/bus.h b/drivers/platform/surface/aggregator/bus.h
  2901. index 6964ee84e79c..5b4dbf21906c 100644
  2902. --- a/drivers/platform/surface/aggregator/bus.h
  2903. +++ b/drivers/platform/surface/aggregator/bus.h
  2904. @@ -2,7 +2,7 @@
  2905. /*
  2906. * Surface System Aggregator Module bus and device integration.
  2907. *
  2908. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2909. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2910. */
  2911. #ifndef _SURFACE_AGGREGATOR_BUS_H
  2912. diff --git a/drivers/platform/surface/aggregator/controller.c b/drivers/platform/surface/aggregator/controller.c
  2913. index 6de834b52b63..43e765199137 100644
  2914. --- a/drivers/platform/surface/aggregator/controller.c
  2915. +++ b/drivers/platform/surface/aggregator/controller.c
  2916. @@ -2,7 +2,7 @@
  2917. /*
  2918. * Main SSAM/SSH controller structure and functionality.
  2919. *
  2920. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2921. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2922. */
  2923. #include <linux/acpi.h>
  2924. diff --git a/drivers/platform/surface/aggregator/controller.h b/drivers/platform/surface/aggregator/controller.h
  2925. index a0963c3562ff..f0d987abc51e 100644
  2926. --- a/drivers/platform/surface/aggregator/controller.h
  2927. +++ b/drivers/platform/surface/aggregator/controller.h
  2928. @@ -2,7 +2,7 @@
  2929. /*
  2930. * Main SSAM/SSH controller structure and functionality.
  2931. *
  2932. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2933. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2934. */
  2935. #ifndef _SURFACE_AGGREGATOR_CONTROLLER_H
  2936. diff --git a/drivers/platform/surface/aggregator/core.c b/drivers/platform/surface/aggregator/core.c
  2937. index a62c5dfe42d6..1a6373dea109 100644
  2938. --- a/drivers/platform/surface/aggregator/core.c
  2939. +++ b/drivers/platform/surface/aggregator/core.c
  2940. @@ -7,7 +7,7 @@
  2941. * Handles communication via requests as well as enabling, disabling, and
  2942. * relaying of events.
  2943. *
  2944. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2945. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2946. */
  2947. #include <linux/acpi.h>
  2948. diff --git a/drivers/platform/surface/aggregator/ssh_msgb.h b/drivers/platform/surface/aggregator/ssh_msgb.h
  2949. index e562958ffdf0..f3ecad92eefd 100644
  2950. --- a/drivers/platform/surface/aggregator/ssh_msgb.h
  2951. +++ b/drivers/platform/surface/aggregator/ssh_msgb.h
  2952. @@ -2,7 +2,7 @@
  2953. /*
  2954. * SSH message builder functions.
  2955. *
  2956. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2957. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2958. */
  2959. #ifndef _SURFACE_AGGREGATOR_SSH_MSGB_H
  2960. diff --git a/drivers/platform/surface/aggregator/ssh_packet_layer.c b/drivers/platform/surface/aggregator/ssh_packet_layer.c
  2961. index 8a4451c1ffe5..6748fe4ac5d5 100644
  2962. --- a/drivers/platform/surface/aggregator/ssh_packet_layer.c
  2963. +++ b/drivers/platform/surface/aggregator/ssh_packet_layer.c
  2964. @@ -2,7 +2,7 @@
  2965. /*
  2966. * SSH packet transport layer.
  2967. *
  2968. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2969. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2970. */
  2971. #include <asm/unaligned.h>
  2972. diff --git a/drivers/platform/surface/aggregator/ssh_packet_layer.h b/drivers/platform/surface/aggregator/ssh_packet_layer.h
  2973. index 2eb329f0b91a..64633522f971 100644
  2974. --- a/drivers/platform/surface/aggregator/ssh_packet_layer.h
  2975. +++ b/drivers/platform/surface/aggregator/ssh_packet_layer.h
  2976. @@ -2,7 +2,7 @@
  2977. /*
  2978. * SSH packet transport layer.
  2979. *
  2980. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2981. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2982. */
  2983. #ifndef _SURFACE_AGGREGATOR_SSH_PACKET_LAYER_H
  2984. diff --git a/drivers/platform/surface/aggregator/ssh_parser.c b/drivers/platform/surface/aggregator/ssh_parser.c
  2985. index b77912f8f13b..a6f668694365 100644
  2986. --- a/drivers/platform/surface/aggregator/ssh_parser.c
  2987. +++ b/drivers/platform/surface/aggregator/ssh_parser.c
  2988. @@ -2,7 +2,7 @@
  2989. /*
  2990. * SSH message parser.
  2991. *
  2992. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  2993. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  2994. */
  2995. #include <asm/unaligned.h>
  2996. diff --git a/drivers/platform/surface/aggregator/ssh_parser.h b/drivers/platform/surface/aggregator/ssh_parser.h
  2997. index 3bd6e180fd16..801d8fa69fb5 100644
  2998. --- a/drivers/platform/surface/aggregator/ssh_parser.h
  2999. +++ b/drivers/platform/surface/aggregator/ssh_parser.h
  3000. @@ -2,7 +2,7 @@
  3001. /*
  3002. * SSH message parser.
  3003. *
  3004. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3005. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3006. */
  3007. #ifndef _SURFACE_AGGREGATOR_SSH_PARSER_H
  3008. diff --git a/drivers/platform/surface/aggregator/ssh_request_layer.c b/drivers/platform/surface/aggregator/ssh_request_layer.c
  3009. index 790f7f0eee98..f5565570f16c 100644
  3010. --- a/drivers/platform/surface/aggregator/ssh_request_layer.c
  3011. +++ b/drivers/platform/surface/aggregator/ssh_request_layer.c
  3012. @@ -2,7 +2,7 @@
  3013. /*
  3014. * SSH request transport layer.
  3015. *
  3016. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3017. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3018. */
  3019. #include <asm/unaligned.h>
  3020. diff --git a/drivers/platform/surface/aggregator/ssh_request_layer.h b/drivers/platform/surface/aggregator/ssh_request_layer.h
  3021. index 9c3cbae2d4bd..4e387a031351 100644
  3022. --- a/drivers/platform/surface/aggregator/ssh_request_layer.h
  3023. +++ b/drivers/platform/surface/aggregator/ssh_request_layer.h
  3024. @@ -2,7 +2,7 @@
  3025. /*
  3026. * SSH request transport layer.
  3027. *
  3028. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3029. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3030. */
  3031. #ifndef _SURFACE_AGGREGATOR_SSH_REQUEST_LAYER_H
  3032. diff --git a/drivers/platform/surface/aggregator/trace.h b/drivers/platform/surface/aggregator/trace.h
  3033. index de64cf169060..7be0bb097dea 100644
  3034. --- a/drivers/platform/surface/aggregator/trace.h
  3035. +++ b/drivers/platform/surface/aggregator/trace.h
  3036. @@ -2,7 +2,7 @@
  3037. /*
  3038. * Trace points for SSAM/SSH.
  3039. *
  3040. - * Copyright (C) 2020-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3041. + * Copyright (C) 2020-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3042. */
  3043. #undef TRACE_SYSTEM
  3044. diff --git a/drivers/platform/surface/surface_acpi_notify.c b/drivers/platform/surface/surface_acpi_notify.c
  3045. index 8339988d95c1..acc958b43b57 100644
  3046. --- a/drivers/platform/surface/surface_acpi_notify.c
  3047. +++ b/drivers/platform/surface/surface_acpi_notify.c
  3048. @@ -8,7 +8,7 @@
  3049. * notifications sent from ACPI via the SAN interface by providing them to any
  3050. * registered external driver.
  3051. *
  3052. - * Copyright (C) 2019-2020 Maximilian Luz <luzmaximilian@gmail.com>
  3053. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3054. */
  3055. #include <asm/unaligned.h>
  3056. diff --git a/drivers/platform/surface/surface_aggregator_cdev.c b/drivers/platform/surface/surface_aggregator_cdev.c
  3057. index 30fb50fde450..492c82e69182 100644
  3058. --- a/drivers/platform/surface/surface_aggregator_cdev.c
  3059. +++ b/drivers/platform/surface/surface_aggregator_cdev.c
  3060. @@ -3,7 +3,7 @@
  3061. * Provides user-space access to the SSAM EC via the /dev/surface/aggregator
  3062. * misc device. Intended for debugging and development.
  3063. *
  3064. - * Copyright (C) 2020-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3065. + * Copyright (C) 2020-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3066. */
  3067. #include <linux/fs.h>
  3068. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  3069. index cee7121e7fa6..3f81db28a702 100644
  3070. --- a/drivers/platform/surface/surface_aggregator_registry.c
  3071. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  3072. @@ -6,7 +6,7 @@
  3073. * cannot be auto-detected. Provides device-hubs and performs instantiation
  3074. * for these devices.
  3075. *
  3076. - * Copyright (C) 2020-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3077. + * Copyright (C) 2020-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3078. */
  3079. #include <linux/acpi.h>
  3080. diff --git a/drivers/platform/surface/surface_dtx.c b/drivers/platform/surface/surface_dtx.c
  3081. index 1203b9a82993..ed36944467f9 100644
  3082. --- a/drivers/platform/surface/surface_dtx.c
  3083. +++ b/drivers/platform/surface/surface_dtx.c
  3084. @@ -8,7 +8,7 @@
  3085. * acknowledge (to speed things up), abort (e.g. in case the dGPU is still in
  3086. * use), or request detachment via user-space.
  3087. *
  3088. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3089. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3090. */
  3091. #include <linux/fs.h>
  3092. diff --git a/drivers/platform/surface/surface_gpe.c b/drivers/platform/surface/surface_gpe.c
  3093. index ec66fde28e75..27365cbe1ee9 100644
  3094. --- a/drivers/platform/surface/surface_gpe.c
  3095. +++ b/drivers/platform/surface/surface_gpe.c
  3096. @@ -4,7 +4,7 @@
  3097. * properly configuring the respective GPEs. Required for wakeup via lid on
  3098. * newer Intel-based Microsoft Surface devices.
  3099. *
  3100. - * Copyright (C) 2020 Maximilian Luz <luzmaximilian@gmail.com>
  3101. + * Copyright (C) 2020-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3102. */
  3103. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  3104. diff --git a/drivers/platform/surface/surface_hotplug.c b/drivers/platform/surface/surface_hotplug.c
  3105. index cfcc15cfbacb..f004a2495201 100644
  3106. --- a/drivers/platform/surface/surface_hotplug.c
  3107. +++ b/drivers/platform/surface/surface_hotplug.c
  3108. @@ -10,7 +10,7 @@
  3109. * Event signaling is handled via ACPI, which will generate the appropriate
  3110. * device-check notifications to be picked up by the PCIe hot-plug driver.
  3111. *
  3112. - * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  3113. + * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3114. */
  3115. #include <linux/acpi.h>
  3116. diff --git a/drivers/platform/surface/surface_platform_profile.c b/drivers/platform/surface/surface_platform_profile.c
  3117. index 6373d3b5eb7f..fbf2e11fd6ce 100644
  3118. --- a/drivers/platform/surface/surface_platform_profile.c
  3119. +++ b/drivers/platform/surface/surface_platform_profile.c
  3120. @@ -3,7 +3,7 @@
  3121. * Surface Platform Profile / Performance Mode driver for Surface System
  3122. * Aggregator Module (thermal subsystem).
  3123. *
  3124. - * Copyright (C) 2021 Maximilian Luz <luzmaximilian@gmail.com>
  3125. + * Copyright (C) 2021-2022 Maximilian Luz <luzmaximilian@gmail.com>
  3126. */
  3127. #include <asm/unaligned.h>
  3128. --
  3129. 2.36.1
  3130. From 9a243e27c34f1cb8a482253473c6170fee0bb27e Mon Sep 17 00:00:00 2001
  3131. From: Maximilian Luz <luzmaximilian@gmail.com>
  3132. Date: Tue, 14 Jun 2022 13:17:49 +0200
  3133. Subject: [PATCH] platform/surface: aggregator: Reserve more event- and
  3134. target-categories
  3135. With the introduction of the Surface Laptop Studio, more event- and
  3136. target categories have been added. Therefore, increase the number of
  3137. reserved events and extend the enum of know target categories.
  3138. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  3139. Patchset: surface-sam
  3140. ---
  3141. drivers/platform/surface/aggregator/trace.h | 80 +++++++++++--------
  3142. include/linux/surface_aggregator/serial_hub.h | 75 +++++++++--------
  3143. 2 files changed, 85 insertions(+), 70 deletions(-)
  3144. diff --git a/drivers/platform/surface/aggregator/trace.h b/drivers/platform/surface/aggregator/trace.h
  3145. index 7be0bb097dea..2a2c17771d01 100644
  3146. --- a/drivers/platform/surface/aggregator/trace.h
  3147. +++ b/drivers/platform/surface/aggregator/trace.h
  3148. @@ -76,7 +76,7 @@ TRACE_DEFINE_ENUM(SSAM_SSH_TC_HID);
  3149. TRACE_DEFINE_ENUM(SSAM_SSH_TC_TCH);
  3150. TRACE_DEFINE_ENUM(SSAM_SSH_TC_BKL);
  3151. TRACE_DEFINE_ENUM(SSAM_SSH_TC_TAM);
  3152. -TRACE_DEFINE_ENUM(SSAM_SSH_TC_ACC);
  3153. +TRACE_DEFINE_ENUM(SSAM_SSH_TC_ACC0);
  3154. TRACE_DEFINE_ENUM(SSAM_SSH_TC_UFI);
  3155. TRACE_DEFINE_ENUM(SSAM_SSH_TC_USC);
  3156. TRACE_DEFINE_ENUM(SSAM_SSH_TC_PEN);
  3157. @@ -85,6 +85,11 @@ TRACE_DEFINE_ENUM(SSAM_SSH_TC_AUD);
  3158. TRACE_DEFINE_ENUM(SSAM_SSH_TC_SMC);
  3159. TRACE_DEFINE_ENUM(SSAM_SSH_TC_KPD);
  3160. TRACE_DEFINE_ENUM(SSAM_SSH_TC_REG);
  3161. +TRACE_DEFINE_ENUM(SSAM_SSH_TC_SPT);
  3162. +TRACE_DEFINE_ENUM(SSAM_SSH_TC_SYS);
  3163. +TRACE_DEFINE_ENUM(SSAM_SSH_TC_ACC1);
  3164. +TRACE_DEFINE_ENUM(SSAM_SSH_TC_SHB);
  3165. +TRACE_DEFINE_ENUM(SSAM_SSH_TC_POS);
  3166. #define SSAM_PTR_UID_LEN 9
  3167. #define SSAM_U8_FIELD_NOT_APPLICABLE ((u16)-1)
  3168. @@ -229,40 +234,45 @@ static inline u32 ssam_trace_get_request_tc(const struct ssh_packet *p)
  3169. #define ssam_show_ssh_tc(rqid) \
  3170. __print_symbolic(rqid, \
  3171. - { SSAM_SSH_TC_NOT_APPLICABLE, "N/A" }, \
  3172. - { SSAM_SSH_TC_SAM, "SAM" }, \
  3173. - { SSAM_SSH_TC_BAT, "BAT" }, \
  3174. - { SSAM_SSH_TC_TMP, "TMP" }, \
  3175. - { SSAM_SSH_TC_PMC, "PMC" }, \
  3176. - { SSAM_SSH_TC_FAN, "FAN" }, \
  3177. - { SSAM_SSH_TC_PoM, "PoM" }, \
  3178. - { SSAM_SSH_TC_DBG, "DBG" }, \
  3179. - { SSAM_SSH_TC_KBD, "KBD" }, \
  3180. - { SSAM_SSH_TC_FWU, "FWU" }, \
  3181. - { SSAM_SSH_TC_UNI, "UNI" }, \
  3182. - { SSAM_SSH_TC_LPC, "LPC" }, \
  3183. - { SSAM_SSH_TC_TCL, "TCL" }, \
  3184. - { SSAM_SSH_TC_SFL, "SFL" }, \
  3185. - { SSAM_SSH_TC_KIP, "KIP" }, \
  3186. - { SSAM_SSH_TC_EXT, "EXT" }, \
  3187. - { SSAM_SSH_TC_BLD, "BLD" }, \
  3188. - { SSAM_SSH_TC_BAS, "BAS" }, \
  3189. - { SSAM_SSH_TC_SEN, "SEN" }, \
  3190. - { SSAM_SSH_TC_SRQ, "SRQ" }, \
  3191. - { SSAM_SSH_TC_MCU, "MCU" }, \
  3192. - { SSAM_SSH_TC_HID, "HID" }, \
  3193. - { SSAM_SSH_TC_TCH, "TCH" }, \
  3194. - { SSAM_SSH_TC_BKL, "BKL" }, \
  3195. - { SSAM_SSH_TC_TAM, "TAM" }, \
  3196. - { SSAM_SSH_TC_ACC, "ACC" }, \
  3197. - { SSAM_SSH_TC_UFI, "UFI" }, \
  3198. - { SSAM_SSH_TC_USC, "USC" }, \
  3199. - { SSAM_SSH_TC_PEN, "PEN" }, \
  3200. - { SSAM_SSH_TC_VID, "VID" }, \
  3201. - { SSAM_SSH_TC_AUD, "AUD" }, \
  3202. - { SSAM_SSH_TC_SMC, "SMC" }, \
  3203. - { SSAM_SSH_TC_KPD, "KPD" }, \
  3204. - { SSAM_SSH_TC_REG, "REG" } \
  3205. + { SSAM_SSH_TC_NOT_APPLICABLE, "N/A" }, \
  3206. + { SSAM_SSH_TC_SAM, "SAM" }, \
  3207. + { SSAM_SSH_TC_BAT, "BAT" }, \
  3208. + { SSAM_SSH_TC_TMP, "TMP" }, \
  3209. + { SSAM_SSH_TC_PMC, "PMC" }, \
  3210. + { SSAM_SSH_TC_FAN, "FAN" }, \
  3211. + { SSAM_SSH_TC_PoM, "PoM" }, \
  3212. + { SSAM_SSH_TC_DBG, "DBG" }, \
  3213. + { SSAM_SSH_TC_KBD, "KBD" }, \
  3214. + { SSAM_SSH_TC_FWU, "FWU" }, \
  3215. + { SSAM_SSH_TC_UNI, "UNI" }, \
  3216. + { SSAM_SSH_TC_LPC, "LPC" }, \
  3217. + { SSAM_SSH_TC_TCL, "TCL" }, \
  3218. + { SSAM_SSH_TC_SFL, "SFL" }, \
  3219. + { SSAM_SSH_TC_KIP, "KIP" }, \
  3220. + { SSAM_SSH_TC_EXT, "EXT" }, \
  3221. + { SSAM_SSH_TC_BLD, "BLD" }, \
  3222. + { SSAM_SSH_TC_BAS, "BAS" }, \
  3223. + { SSAM_SSH_TC_SEN, "SEN" }, \
  3224. + { SSAM_SSH_TC_SRQ, "SRQ" }, \
  3225. + { SSAM_SSH_TC_MCU, "MCU" }, \
  3226. + { SSAM_SSH_TC_HID, "HID" }, \
  3227. + { SSAM_SSH_TC_TCH, "TCH" }, \
  3228. + { SSAM_SSH_TC_BKL, "BKL" }, \
  3229. + { SSAM_SSH_TC_TAM, "TAM" }, \
  3230. + { SSAM_SSH_TC_ACC0, "ACC0" }, \
  3231. + { SSAM_SSH_TC_UFI, "UFI" }, \
  3232. + { SSAM_SSH_TC_USC, "USC" }, \
  3233. + { SSAM_SSH_TC_PEN, "PEN" }, \
  3234. + { SSAM_SSH_TC_VID, "VID" }, \
  3235. + { SSAM_SSH_TC_AUD, "AUD" }, \
  3236. + { SSAM_SSH_TC_SMC, "SMC" }, \
  3237. + { SSAM_SSH_TC_KPD, "KPD" }, \
  3238. + { SSAM_SSH_TC_REG, "REG" }, \
  3239. + { SSAM_SSH_TC_SPT, "SPT" }, \
  3240. + { SSAM_SSH_TC_SYS, "SYS" }, \
  3241. + { SSAM_SSH_TC_ACC1, "ACC1" }, \
  3242. + { SSAM_SSH_TC_SHB, "SMB" }, \
  3243. + { SSAM_SSH_TC_POS, "POS" } \
  3244. )
  3245. DECLARE_EVENT_CLASS(ssam_frame_class,
  3246. diff --git a/include/linux/surface_aggregator/serial_hub.h b/include/linux/surface_aggregator/serial_hub.h
  3247. index 26b95ec12733..45501b6e54e8 100644
  3248. --- a/include/linux/surface_aggregator/serial_hub.h
  3249. +++ b/include/linux/surface_aggregator/serial_hub.h
  3250. @@ -201,7 +201,7 @@ static inline u16 ssh_crc(const u8 *buf, size_t len)
  3251. * exception of zero, which is not an event ID. Thus, this is also the
  3252. * absolute maximum number of event handlers that can be registered.
  3253. */
  3254. -#define SSH_NUM_EVENTS 34
  3255. +#define SSH_NUM_EVENTS 38
  3256. /*
  3257. * SSH_NUM_TARGETS - The number of communication targets used in the protocol.
  3258. @@ -292,40 +292,45 @@ struct ssam_span {
  3259. * Windows driver.
  3260. */
  3261. enum ssam_ssh_tc {
  3262. - /* Category 0x00 is invalid for EC use. */
  3263. - SSAM_SSH_TC_SAM = 0x01, /* Generic system functionality, real-time clock. */
  3264. - SSAM_SSH_TC_BAT = 0x02, /* Battery/power subsystem. */
  3265. - SSAM_SSH_TC_TMP = 0x03, /* Thermal subsystem. */
  3266. - SSAM_SSH_TC_PMC = 0x04,
  3267. - SSAM_SSH_TC_FAN = 0x05,
  3268. - SSAM_SSH_TC_PoM = 0x06,
  3269. - SSAM_SSH_TC_DBG = 0x07,
  3270. - SSAM_SSH_TC_KBD = 0x08, /* Legacy keyboard (Laptop 1/2). */
  3271. - SSAM_SSH_TC_FWU = 0x09,
  3272. - SSAM_SSH_TC_UNI = 0x0a,
  3273. - SSAM_SSH_TC_LPC = 0x0b,
  3274. - SSAM_SSH_TC_TCL = 0x0c,
  3275. - SSAM_SSH_TC_SFL = 0x0d,
  3276. - SSAM_SSH_TC_KIP = 0x0e, /* Manages detachable peripherals (Pro X/8 keyboard cover) */
  3277. - SSAM_SSH_TC_EXT = 0x0f,
  3278. - SSAM_SSH_TC_BLD = 0x10,
  3279. - SSAM_SSH_TC_BAS = 0x11, /* Detachment system (Surface Book 2/3). */
  3280. - SSAM_SSH_TC_SEN = 0x12,
  3281. - SSAM_SSH_TC_SRQ = 0x13,
  3282. - SSAM_SSH_TC_MCU = 0x14,
  3283. - SSAM_SSH_TC_HID = 0x15, /* Generic HID input subsystem. */
  3284. - SSAM_SSH_TC_TCH = 0x16,
  3285. - SSAM_SSH_TC_BKL = 0x17,
  3286. - SSAM_SSH_TC_TAM = 0x18,
  3287. - SSAM_SSH_TC_ACC = 0x19,
  3288. - SSAM_SSH_TC_UFI = 0x1a,
  3289. - SSAM_SSH_TC_USC = 0x1b,
  3290. - SSAM_SSH_TC_PEN = 0x1c,
  3291. - SSAM_SSH_TC_VID = 0x1d,
  3292. - SSAM_SSH_TC_AUD = 0x1e,
  3293. - SSAM_SSH_TC_SMC = 0x1f,
  3294. - SSAM_SSH_TC_KPD = 0x20,
  3295. - SSAM_SSH_TC_REG = 0x21, /* Extended event registry. */
  3296. + /* Category 0x00 is invalid for EC use. */
  3297. + SSAM_SSH_TC_SAM = 0x01, /* Generic system functionality, real-time clock. */
  3298. + SSAM_SSH_TC_BAT = 0x02, /* Battery/power subsystem. */
  3299. + SSAM_SSH_TC_TMP = 0x03, /* Thermal subsystem. */
  3300. + SSAM_SSH_TC_PMC = 0x04,
  3301. + SSAM_SSH_TC_FAN = 0x05,
  3302. + SSAM_SSH_TC_PoM = 0x06,
  3303. + SSAM_SSH_TC_DBG = 0x07,
  3304. + SSAM_SSH_TC_KBD = 0x08, /* Legacy keyboard (Laptop 1/2). */
  3305. + SSAM_SSH_TC_FWU = 0x09,
  3306. + SSAM_SSH_TC_UNI = 0x0a,
  3307. + SSAM_SSH_TC_LPC = 0x0b,
  3308. + SSAM_SSH_TC_TCL = 0x0c,
  3309. + SSAM_SSH_TC_SFL = 0x0d,
  3310. + SSAM_SSH_TC_KIP = 0x0e, /* Manages detachable peripherals (Pro X/8 keyboard cover) */
  3311. + SSAM_SSH_TC_EXT = 0x0f,
  3312. + SSAM_SSH_TC_BLD = 0x10,
  3313. + SSAM_SSH_TC_BAS = 0x11, /* Detachment system (Surface Book 2/3). */
  3314. + SSAM_SSH_TC_SEN = 0x12,
  3315. + SSAM_SSH_TC_SRQ = 0x13,
  3316. + SSAM_SSH_TC_MCU = 0x14,
  3317. + SSAM_SSH_TC_HID = 0x15, /* Generic HID input subsystem. */
  3318. + SSAM_SSH_TC_TCH = 0x16,
  3319. + SSAM_SSH_TC_BKL = 0x17,
  3320. + SSAM_SSH_TC_TAM = 0x18,
  3321. + SSAM_SSH_TC_ACC0 = 0x19,
  3322. + SSAM_SSH_TC_UFI = 0x1a,
  3323. + SSAM_SSH_TC_USC = 0x1b,
  3324. + SSAM_SSH_TC_PEN = 0x1c,
  3325. + SSAM_SSH_TC_VID = 0x1d,
  3326. + SSAM_SSH_TC_AUD = 0x1e,
  3327. + SSAM_SSH_TC_SMC = 0x1f,
  3328. + SSAM_SSH_TC_KPD = 0x20,
  3329. + SSAM_SSH_TC_REG = 0x21, /* Extended event registry. */
  3330. + SSAM_SSH_TC_SPT = 0x22,
  3331. + SSAM_SSH_TC_SYS = 0x23,
  3332. + SSAM_SSH_TC_ACC1 = 0x24,
  3333. + SSAM_SSH_TC_SHB = 0x25,
  3334. + SSAM_SSH_TC_POS = 0x26, /* For obtaining Laptop Studio screen position. */
  3335. };
  3336. --
  3337. 2.36.1