0011-amd-gpio.patch 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. From db59de04463e7daf9db5d6a94ecade027c386bf5 Mon Sep 17 00:00:00 2001
  2. From: Sachi King <nakato@nakato.io>
  3. Date: Sat, 29 May 2021 17:47:38 +1000
  4. Subject: [PATCH] ACPI: Add quirk for Surface Laptop 4 AMD missing irq 7
  5. override
  6. This patch is the work of Thomas Gleixner <tglx@linutronix.de> and is
  7. copied from:
  8. https://lore.kernel.org/lkml/87lf8ddjqx.ffs@nanos.tec.linutronix.de/
  9. This patch adds a quirk to the ACPI setup to patch in the the irq 7 pin
  10. setup that is missing in the laptops ACPI table.
  11. This patch was used for validation of the issue, and is not a proper
  12. fix, but is probably a better temporary hack than continuing to probe
  13. the Legacy PIC and run with the PIC in an unknown state.
  14. Patchset: amd-gpio
  15. ---
  16. arch/x86/kernel/acpi/boot.c | 17 +++++++++++++++++
  17. 1 file changed, 17 insertions(+)
  18. diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
  19. index e55e0c1fad8c..46dfad41b401 100644
  20. --- a/arch/x86/kernel/acpi/boot.c
  21. +++ b/arch/x86/kernel/acpi/boot.c
  22. @@ -22,6 +22,7 @@
  23. #include <linux/efi-bgrt.h>
  24. #include <linux/serial_core.h>
  25. #include <linux/pgtable.h>
  26. +#include <linux/dmi.h>
  27. #include <asm/e820/api.h>
  28. #include <asm/irqdomain.h>
  29. @@ -1143,6 +1144,17 @@ static void __init mp_config_acpi_legacy_irqs(void)
  30. }
  31. }
  32. +static const struct dmi_system_id surface_quirk[] __initconst = {
  33. + {
  34. + .ident = "Microsoft Surface Laptop 4 (AMD)",
  35. + .matches = {
  36. + DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
  37. + DMI_MATCH(DMI_PRODUCT_SKU, "Surface_Laptop_4_1952:1953")
  38. + },
  39. + },
  40. + {}
  41. +};
  42. +
  43. /*
  44. * Parse IOAPIC related entries in MADT
  45. * returns 0 on success, < 0 on error
  46. @@ -1198,6 +1210,11 @@ static int __init acpi_parse_madt_ioapic_entries(void)
  47. acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
  48. acpi_gbl_FADT.sci_interrupt);
  49. + if (dmi_check_system(surface_quirk)) {
  50. + pr_warn("Surface hack: Override irq 7\n");
  51. + mp_override_legacy_irq(7, 3, 3, 7);
  52. + }
  53. +
  54. /* Fill in identity legacy mappings where no override */
  55. mp_config_acpi_legacy_irqs();
  56. --
  57. 2.33.1
  58. From f36c217ee9cf09a3eeb0c4c869823fe4abe53c87 Mon Sep 17 00:00:00 2001
  59. From: Maximilian Luz <luzmaximilian@gmail.com>
  60. Date: Thu, 3 Jun 2021 14:04:26 +0200
  61. Subject: [PATCH] ACPI: Add AMD 13" Surface Laptop 4 model to irq 7 override
  62. quirk
  63. The 13" version of the Surface Laptop 4 has the same problem as the 15"
  64. version, but uses a different SKU. Add that SKU to the quirk as well.
  65. Patchset: amd-gpio
  66. ---
  67. arch/x86/kernel/acpi/boot.c | 9 ++++++++-
  68. 1 file changed, 8 insertions(+), 1 deletion(-)
  69. diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
  70. index 46dfad41b401..78bf6a097dc5 100644
  71. --- a/arch/x86/kernel/acpi/boot.c
  72. +++ b/arch/x86/kernel/acpi/boot.c
  73. @@ -1146,12 +1146,19 @@ static void __init mp_config_acpi_legacy_irqs(void)
  74. static const struct dmi_system_id surface_quirk[] __initconst = {
  75. {
  76. - .ident = "Microsoft Surface Laptop 4 (AMD)",
  77. + .ident = "Microsoft Surface Laptop 4 (AMD 15\")",
  78. .matches = {
  79. DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
  80. DMI_MATCH(DMI_PRODUCT_SKU, "Surface_Laptop_4_1952:1953")
  81. },
  82. },
  83. + {
  84. + .ident = "Microsoft Surface Laptop 4 (AMD 13\")",
  85. + .matches = {
  86. + DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
  87. + DMI_MATCH(DMI_PRODUCT_SKU, "Surface_Laptop_4_1958:1959")
  88. + },
  89. + },
  90. {}
  91. };
  92. --
  93. 2.33.1
  94. From fa0275eafbc5171767f6bc3fd9ca2dba2940ccc6 Mon Sep 17 00:00:00 2001
  95. From: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
  96. Date: Tue, 31 Aug 2021 17:36:12 +0530
  97. Subject: [PATCH] pinctrl: amd: Add irq field data
  98. pinctrl_amd use gpiochip_get_data() to get their local state containers
  99. back from the gpiochip passed as amd_gpio chip data.
  100. Hence added irq field data to get directly using amd_gpio chip data.
  101. Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
  102. Patchset: amd-gpio
  103. ---
  104. drivers/pinctrl/pinctrl-amd.c | 9 ++++-----
  105. drivers/pinctrl/pinctrl-amd.h | 1 +
  106. 2 files changed, 5 insertions(+), 5 deletions(-)
  107. diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
  108. index 5b764740b829..79b8b7f91996 100644
  109. --- a/drivers/pinctrl/pinctrl-amd.c
  110. +++ b/drivers/pinctrl/pinctrl-amd.c
  111. @@ -904,7 +904,6 @@ static struct pinctrl_desc amd_pinctrl_desc = {
  112. static int amd_gpio_probe(struct platform_device *pdev)
  113. {
  114. int ret = 0;
  115. - int irq_base;
  116. struct resource *res;
  117. struct amd_gpio *gpio_dev;
  118. struct gpio_irq_chip *girq;
  119. @@ -927,9 +926,9 @@ static int amd_gpio_probe(struct platform_device *pdev)
  120. if (!gpio_dev->base)
  121. return -ENOMEM;
  122. - irq_base = platform_get_irq(pdev, 0);
  123. - if (irq_base < 0)
  124. - return irq_base;
  125. + gpio_dev->irq = platform_get_irq(pdev, 0);
  126. + if (gpio_dev->irq < 0)
  127. + return gpio_dev->irq;
  128. #ifdef CONFIG_PM_SLEEP
  129. gpio_dev->saved_regs = devm_kcalloc(&pdev->dev, amd_pinctrl_desc.npins,
  130. @@ -989,7 +988,7 @@ static int amd_gpio_probe(struct platform_device *pdev)
  131. goto out2;
  132. }
  133. - ret = devm_request_irq(&pdev->dev, irq_base, amd_gpio_irq_handler,
  134. + ret = devm_request_irq(&pdev->dev, gpio_dev->irq, amd_gpio_irq_handler,
  135. IRQF_SHARED, KBUILD_MODNAME, gpio_dev);
  136. if (ret)
  137. goto out2;
  138. diff --git a/drivers/pinctrl/pinctrl-amd.h b/drivers/pinctrl/pinctrl-amd.h
  139. index 95e763424042..1d4317073654 100644
  140. --- a/drivers/pinctrl/pinctrl-amd.h
  141. +++ b/drivers/pinctrl/pinctrl-amd.h
  142. @@ -98,6 +98,7 @@ struct amd_gpio {
  143. struct resource *res;
  144. struct platform_device *pdev;
  145. u32 *saved_regs;
  146. + int irq;
  147. };
  148. /* KERNCZ configuration*/
  149. --
  150. 2.33.1
  151. From d1b2d9b220465e1f8abb62f07f461b1c2374d66b Mon Sep 17 00:00:00 2001
  152. From: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
  153. Date: Tue, 31 Aug 2021 17:36:13 +0530
  154. Subject: [PATCH] pinctrl: amd: Handle wake-up interrupt
  155. Enable/disable power management wakeup mode, which is disabled by
  156. default. enable_irq_wake enables wakes the system from sleep.
  157. Hence added enable/disable irq_wake to handle wake-up interrupt.
  158. Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
  159. Patchset: amd-gpio
  160. ---
  161. drivers/pinctrl/pinctrl-amd.c | 10 ++++++++++
  162. 1 file changed, 10 insertions(+)
  163. diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
  164. index 79b8b7f91996..d19974aceb2e 100644
  165. --- a/drivers/pinctrl/pinctrl-amd.c
  166. +++ b/drivers/pinctrl/pinctrl-amd.c
  167. @@ -445,6 +445,7 @@ static int amd_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
  168. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  169. struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
  170. u32 wake_mask = BIT(WAKE_CNTRL_OFF_S0I3) | BIT(WAKE_CNTRL_OFF_S3);
  171. + int err;
  172. raw_spin_lock_irqsave(&gpio_dev->lock, flags);
  173. pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
  174. @@ -457,6 +458,15 @@ static int amd_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
  175. writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
  176. raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
  177. + if (on)
  178. + err = enable_irq_wake(gpio_dev->irq);
  179. + else
  180. + err = disable_irq_wake(gpio_dev->irq);
  181. +
  182. + if (err)
  183. + dev_err(&gpio_dev->pdev->dev, "failed to %s wake-up interrupt\n",
  184. + on ? "enable" : "disable");
  185. +
  186. return 0;
  187. }
  188. --
  189. 2.33.1
  190. From f429b5104b297a4b817df233dc77665c48c31184 Mon Sep 17 00:00:00 2001
  191. From: Sachi King <nakato@nakato.io>
  192. Date: Fri, 1 Oct 2021 21:19:09 +1000
  193. Subject: [PATCH] pinctrl: amd: disable and mask interrupts on probe
  194. Some systems such as the Microsoft Surface Laptop 4 leave interrupts
  195. enabled and configured for use in sleep states on boot, which cause
  196. unexpected behaviour such as spurious wakes and failed resumes in
  197. s2idle states.
  198. As interrupts should not be enabled until they are claimed and
  199. explicitly enabled, disabling any interrupts mistakenly left enabled by
  200. firmware should be safe.
  201. Signed-off-by: Sachi King <nakato@nakato.io>
  202. Patchset: amd-gpio
  203. ---
  204. drivers/pinctrl/pinctrl-amd.c | 29 +++++++++++++++++++++++++++++
  205. 1 file changed, 29 insertions(+)
  206. diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
  207. index d19974aceb2e..d32daf1c862f 100644
  208. --- a/drivers/pinctrl/pinctrl-amd.c
  209. +++ b/drivers/pinctrl/pinctrl-amd.c
  210. @@ -842,6 +842,32 @@ static const struct pinconf_ops amd_pinconf_ops = {
  211. .pin_config_group_set = amd_pinconf_group_set,
  212. };
  213. +static void amd_gpio_irq_init(struct amd_gpio *gpio_dev) {
  214. + struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
  215. + unsigned long flags;
  216. + u32 pin_reg, mask;
  217. + int i;
  218. +
  219. + mask = BIT(WAKE_CNTRL_OFF_S0I3) | BIT(WAKE_CNTRL_OFF_S3)
  220. + | BIT(INTERRUPT_MASK_OFF) | BIT(INTERRUPT_ENABLE_OFF)
  221. + | BIT(INTERRUPT_MASK_OFF) | BIT(WAKE_CNTRL_OFF_S4);
  222. +
  223. + for (i = 0; i < desc->npins; i++) {
  224. + int pin = desc->pins[i].number;
  225. + const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
  226. + if (!pd)
  227. + continue;
  228. +
  229. + raw_spin_lock_irqsave(&gpio_dev->lock, flags);
  230. +
  231. + pin_reg = readl(gpio_dev->base + i * 4);
  232. + pin_reg &= ~mask;
  233. + writel(pin_reg, gpio_dev->base + i * 4);
  234. +
  235. + raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
  236. + }
  237. +}
  238. +
  239. #ifdef CONFIG_PM_SLEEP
  240. static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin)
  241. {
  242. @@ -978,6 +1004,9 @@ static int amd_gpio_probe(struct platform_device *pdev)
  243. return PTR_ERR(gpio_dev->pctrl);
  244. }
  245. + /* Disable and mask interrupts */
  246. + amd_gpio_irq_init(gpio_dev);
  247. +
  248. girq = &gpio_dev->gc.irq;
  249. girq->chip = &amd_gpio_irqchip;
  250. /* This will let us handle the parent IRQ in the driver */
  251. --
  252. 2.33.1