0007-surface-sam.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. From 743c35534434dc42eecd818a5d6d02f33032f2f7 Mon Sep 17 00:00:00 2001
  2. From: Maximilian Luz <luzmaximilian@gmail.com>
  3. Date: Fri, 17 Jun 2022 02:14:00 +0200
  4. Subject: [PATCH] rtc: Add basic support for RTC via Surface System Aggregator
  5. Module
  6. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  7. Patchset: surface-sam
  8. ---
  9. drivers/rtc/Kconfig | 7 +++
  10. drivers/rtc/Makefile | 1 +
  11. drivers/rtc/rtc-surface.c | 129 ++++++++++++++++++++++++++++++++++++++
  12. 3 files changed, 137 insertions(+)
  13. create mode 100644 drivers/rtc/rtc-surface.c
  14. diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
  15. index a60bcc791a48..2de96e4c1ba6 100644
  16. --- a/drivers/rtc/Kconfig
  17. +++ b/drivers/rtc/Kconfig
  18. @@ -1383,6 +1383,13 @@ config RTC_DRV_NTXEC
  19. embedded controller found in certain e-book readers designed by the
  20. original design manufacturer Netronix.
  21. +config RTC_DRV_SURFACE
  22. + tristate "Microsoft Surface Aggregator RTC"
  23. + depends on SURFACE_AGGREGATOR
  24. + depends on SURFACE_AGGREGATOR_BUS
  25. + help
  26. + TODO
  27. +
  28. comment "on-CPU RTC drivers"
  29. config RTC_DRV_ASM9260
  30. diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
  31. index 489b4ab07068..061afa9db5b6 100644
  32. --- a/drivers/rtc/Makefile
  33. +++ b/drivers/rtc/Makefile
  34. @@ -180,6 +180,7 @@ obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o
  35. obj-$(CONFIG_RTC_DRV_SUN6I) += rtc-sun6i.o
  36. obj-$(CONFIG_RTC_DRV_SUNPLUS) += rtc-sunplus.o
  37. obj-$(CONFIG_RTC_DRV_SUNXI) += rtc-sunxi.o
  38. +obj-$(CONFIG_RTC_DRV_SURFACE) += rtc-surface.o
  39. obj-$(CONFIG_RTC_DRV_TEGRA) += rtc-tegra.o
  40. obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
  41. obj-$(CONFIG_RTC_DRV_TI_K3) += rtc-ti-k3.o
  42. diff --git a/drivers/rtc/rtc-surface.c b/drivers/rtc/rtc-surface.c
  43. new file mode 100644
  44. index 000000000000..f6c17c4e98d5
  45. --- /dev/null
  46. +++ b/drivers/rtc/rtc-surface.c
  47. @@ -0,0 +1,129 @@
  48. +// SPDX-License-Identifier: GPL-2.0+
  49. +/*
  50. + * AC driver for 7th-generation Microsoft Surface devices via Surface System
  51. + * Aggregator Module (SSAM).
  52. + *
  53. + * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
  54. + */
  55. +
  56. +#include <linux/kernel.h>
  57. +#include <linux/module.h>
  58. +#include <linux/rtc.h>
  59. +#include <linux/slab.h>
  60. +#include <linux/types.h>
  61. +
  62. +#include <linux/surface_aggregator/device.h>
  63. +
  64. +struct surface_rtc {
  65. + struct ssam_device *sdev;
  66. + struct rtc_device *rtc;
  67. +};
  68. +
  69. +SSAM_DEFINE_SYNC_REQUEST_R(__ssam_rtc_get_unix_time, __le32, {
  70. + .target_category = SSAM_SSH_TC_SAM,
  71. + .target_id = SSAM_SSH_TID_SAM,
  72. + .instance_id = 0x00,
  73. + .command_id = 0x10,
  74. +});
  75. +
  76. +SSAM_DEFINE_SYNC_REQUEST_W(__ssam_rtc_set_unix_time, __le32, {
  77. + .target_category = SSAM_SSH_TC_SAM,
  78. + .target_id = SSAM_SSH_TID_SAM,
  79. + .instance_id = 0x00,
  80. + .command_id = 0x0f,
  81. +});
  82. +
  83. +static int ssam_rtc_get_unix_time(struct surface_rtc *srtc, u32 *time)
  84. +{
  85. + __le32 time_le;
  86. + int status;
  87. +
  88. + status = __ssam_rtc_get_unix_time(srtc->sdev->ctrl, &time_le);
  89. + if (status)
  90. + return status;
  91. +
  92. + *time = le32_to_cpu(time_le);
  93. + return 0;
  94. +}
  95. +
  96. +static int ssam_rtc_set_unix_time(struct surface_rtc *srtc, u32 time)
  97. +{
  98. + __le32 time_le = cpu_to_le32(time);
  99. +
  100. + return __ssam_rtc_set_unix_time(srtc->sdev->ctrl, &time_le);
  101. +}
  102. +
  103. +static int surface_rtc_read_time(struct device *dev, struct rtc_time *tm)
  104. +{
  105. + struct surface_rtc *srtc = dev_get_drvdata(dev);
  106. + int status;
  107. + u32 time;
  108. +
  109. + status = ssam_rtc_get_unix_time(srtc, &time);
  110. + if (status)
  111. + return status;
  112. +
  113. + rtc_time64_to_tm(time, tm);
  114. + return 0;
  115. +}
  116. +
  117. +static int surface_rtc_set_time(struct device *dev, struct rtc_time *tm)
  118. +{
  119. + struct surface_rtc *srtc = dev_get_drvdata(dev);
  120. + time64_t time = rtc_tm_to_time64(tm);
  121. +
  122. + return ssam_rtc_set_unix_time(srtc, (u32)time);
  123. +}
  124. +
  125. +static const struct rtc_class_ops surface_rtc_ops = {
  126. + .read_time = surface_rtc_read_time,
  127. + .set_time = surface_rtc_set_time,
  128. +};
  129. +
  130. +static int surface_rtc_probe(struct ssam_device *sdev)
  131. +{
  132. + struct surface_rtc *srtc;
  133. +
  134. + srtc = devm_kzalloc(&sdev->dev, sizeof(*srtc), GFP_KERNEL);
  135. + if (!srtc)
  136. + return -ENOMEM;
  137. +
  138. + srtc->sdev = sdev;
  139. +
  140. + srtc->rtc = devm_rtc_allocate_device(&sdev->dev);
  141. + if (IS_ERR(srtc->rtc))
  142. + return PTR_ERR(srtc->rtc);
  143. +
  144. + srtc->rtc->ops = &surface_rtc_ops;
  145. + srtc->rtc->range_max = U32_MAX;
  146. +
  147. + ssam_device_set_drvdata(sdev, srtc);
  148. +
  149. + return devm_rtc_register_device(srtc->rtc);
  150. +}
  151. +
  152. +static void surface_rtc_remove(struct ssam_device *sdev)
  153. +{
  154. + /* Device-managed allocations take care of everything... */
  155. +}
  156. +
  157. +static const struct ssam_device_id surface_rtc_match[] = {
  158. + { SSAM_SDEV(SAM, SAM, 0x00, 0x00) },
  159. + { },
  160. +};
  161. +MODULE_DEVICE_TABLE(ssam, surface_rtc_match);
  162. +
  163. +static struct ssam_device_driver surface_rtc_driver = {
  164. + .probe = surface_rtc_probe,
  165. + .remove = surface_rtc_remove,
  166. + .match_table = surface_rtc_match,
  167. + .driver = {
  168. + .name = "surface_rtc",
  169. + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  170. + },
  171. +};
  172. +module_ssam_device_driver(surface_rtc_driver);
  173. +
  174. +MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
  175. +MODULE_DESCRIPTION("RTC driver for Surface System Aggregator Module");
  176. +MODULE_LICENSE("GPL");
  177. --
  178. 2.49.0
  179. From 47fccc8a7d20139c64577c160bc56eaf4bc2b953 Mon Sep 17 00:00:00 2001
  180. From: Maximilian Luz <luzmaximilian@gmail.com>
  181. Date: Sun, 20 Apr 2025 01:05:14 +0200
  182. Subject: [PATCH] platform/surface: aggregator_registry: Add Surface Laptop 7
  183. (ACPI)
  184. Patchset: surface-sam
  185. ---
  186. drivers/platform/surface/surface_aggregator_registry.c | 3 +++
  187. 1 file changed, 3 insertions(+)
  188. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  189. index a594d5fcfcfd..07b03aa4fa7f 100644
  190. --- a/drivers/platform/surface/surface_aggregator_registry.c
  191. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  192. @@ -460,6 +460,9 @@ static const struct acpi_device_id ssam_platform_hub_acpi_match[] = {
  193. /* Surface Laptop 6 */
  194. { "MSHW0530", (unsigned long)ssam_node_group_sl6 },
  195. + /* Surface Laptop 7 */
  196. + { "MSHW0551", (unsigned long)ssam_node_group_sl7 },
  197. +
  198. /* Surface Laptop Go 1 */
  199. { "MSHW0118", (unsigned long)ssam_node_group_slg1 },
  200. --
  201. 2.49.0