[v3,1/2] platform/x86: surfacepro3_button: Fix device check
diff mbox series

Message ID 20190720150511.95076-2-luzmaximilian@gmail.com
State New
Headers show
Series
  • Support for buttons on newer MS Surface devices
Related show

Commit Message

Maximilian Luz July 20, 2019, 3:05 p.m. UTC
Do not use the surfacepro3_button driver on newer Microsoft Surface
models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th
and possibly future generations) use the same device as the Surface Pro
4 to represent their volume and power buttons (MSHW0040), but their
actual implementation is significantly different. This patch ensures
that the surfacepro3_button driver is only used on the Pro 3 and 4
models, allowing a different driver to bind on other models.

Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
---
 drivers/platform/x86/surfacepro3_button.c | 47 +++++++++++++++++++++++
 1 file changed, 47 insertions(+)

Comments

Andy Shevchenko July 25, 2019, 5:57 p.m. UTC | #1
On Sat, Jul 20, 2019 at 6:05 PM Maximilian Luz <luzmaximilian@gmail.com> wrote:
>
> Do not use the surfacepro3_button driver on newer Microsoft Surface
> models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th
> and possibly future generations) use the same device as the Surface Pro
> 4 to represent their volume and power buttons (MSHW0040), but their
> actual implementation is significantly different. This patch ensures
> that the surfacepro3_button driver is only used on the Pro 3 and 4
> models, allowing a different driver to bind on other models.
>

Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>

assuming it will go thru Input subsystem.

> Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
> ---
>  drivers/platform/x86/surfacepro3_button.c | 47 +++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
>
> diff --git a/drivers/platform/x86/surfacepro3_button.c b/drivers/platform/x86/surfacepro3_button.c
> index 47c6d000465a..ec515223f654 100644
> --- a/drivers/platform/x86/surfacepro3_button.c
> +++ b/drivers/platform/x86/surfacepro3_button.c
> @@ -20,6 +20,12 @@
>  #define SURFACE_BUTTON_OBJ_NAME                "VGBI"
>  #define SURFACE_BUTTON_DEVICE_NAME     "Surface Pro 3/4 Buttons"
>
> +#define MSHW0040_DSM_REVISION          0x01
> +#define MSHW0040_DSM_GET_OMPR          0x02    // get OEM Platform Revision
> +static const guid_t MSHW0040_DSM_UUID =
> +       GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4, 0x95, 0xed, 0xab, 0x16, 0x65,
> +                 0x49, 0x80, 0x35);
> +
>  #define SURFACE_BUTTON_NOTIFY_TABLET_MODE      0xc8
>
>  #define SURFACE_BUTTON_NOTIFY_PRESS_POWER      0xc6
> @@ -142,6 +148,44 @@ static int surface_button_resume(struct device *dev)
>  }
>  #endif
>
> +/*
> + * Surface Pro 4 and Surface Book 2 / Surface Pro 2017 use the same device
> + * ID (MSHW0040) for the power/volume buttons. Make sure this is the right
> + * device by checking for the _DSM method and OEM Platform Revision.
> + *
> + * Returns true if the driver should bind to this device, i.e. the device is
> + * either MSWH0028 (Pro 3) or MSHW0040 on a Pro 4 or Book 1.
> + */
> +static bool surface_button_check_MSHW0040(struct acpi_device *dev)
> +{
> +       acpi_handle handle = dev->handle;
> +       union acpi_object *result;
> +       u64 oem_platform_rev = 0;       // valid revisions are nonzero
> +
> +       // get OEM platform revision
> +       result = acpi_evaluate_dsm_typed(handle, &MSHW0040_DSM_UUID,
> +                                        MSHW0040_DSM_REVISION,
> +                                        MSHW0040_DSM_GET_OMPR,
> +                                        NULL, ACPI_TYPE_INTEGER);
> +
> +       /*
> +        * If evaluating the _DSM fails, the method is not present. This means
> +        * that we have either MSHW0028 or MSHW0040 on Pro 4 or Book 1, so we
> +        * should use this driver. We use revision 0 indicating it is
> +        * unavailable.
> +        */
> +
> +       if (result) {
> +               oem_platform_rev = result->integer.value;
> +               ACPI_FREE(result);
> +       }
> +
> +       dev_dbg(&dev->dev, "OEM Platform Revision %llu\n", oem_platform_rev);
> +
> +       return oem_platform_rev == 0;
> +}
> +
> +
>  static int surface_button_add(struct acpi_device *device)
>  {
>         struct surface_button *button;
> @@ -154,6 +198,9 @@ static int surface_button_add(struct acpi_device *device)
>             strlen(SURFACE_BUTTON_OBJ_NAME)))
>                 return -ENODEV;
>
> +       if (!surface_button_check_MSHW0040(device))
> +               return -ENODEV;
> +
>         button = kzalloc(sizeof(struct surface_button), GFP_KERNEL);
>         if (!button)
>                 return -ENOMEM;
> --
> 2.22.0
>
Chen Yu July 26, 2019, 1:48 a.m. UTC | #2
On Sat, Jul 20, 2019 at 05:05:10PM +0200, Maximilian Luz wrote:
> Do not use the surfacepro3_button driver on newer Microsoft Surface
> models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th
> and possibly future generations) use the same device as the Surface Pro
> 4 to represent their volume and power buttons (MSHW0040), but their
> actual implementation is significantly different. This patch ensures
> that the surfacepro3_button driver is only used on the Pro 3 and 4
> models, allowing a different driver to bind on other models.
> 
> Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
> ---
Acked-by: Chen Yu <yu.c.chen@intel.com>

Thanks,
Chenyu
Dmitry Torokhov July 27, 2019, 9:15 a.m. UTC | #3
On Thu, Jul 25, 2019 at 08:57:53PM +0300, Andy Shevchenko wrote:
> On Sat, Jul 20, 2019 at 6:05 PM Maximilian Luz <luzmaximilian@gmail.com> wrote:
> >
> > Do not use the surfacepro3_button driver on newer Microsoft Surface
> > models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th
> > and possibly future generations) use the same device as the Surface Pro
> > 4 to represent their volume and power buttons (MSHW0040), but their
> > actual implementation is significantly different. This patch ensures
> > that the surfacepro3_button driver is only used on the Pro 3 and 4
> > models, allowing a different driver to bind on other models.
> >
> 
> Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> 
> assuming it will go thru Input subsystem.

I can take it, but I do not think it is dependent on the other change
and thus can go through platform tree as well.

Thanks.
Andy Shevchenko July 27, 2019, 12:26 p.m. UTC | #4
On Sat, Jul 27, 2019 at 12:15 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> On Thu, Jul 25, 2019 at 08:57:53PM +0300, Andy Shevchenko wrote:
> > On Sat, Jul 20, 2019 at 6:05 PM Maximilian Luz <luzmaximilian@gmail.com> wrote:
> > >
> > > Do not use the surfacepro3_button driver on newer Microsoft Surface
> > > models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th
> > > and possibly future generations) use the same device as the Surface Pro
> > > 4 to represent their volume and power buttons (MSHW0040), but their
> > > actual implementation is significantly different. This patch ensures
> > > that the surfacepro3_button driver is only used on the Pro 3 and 4
> > > models, allowing a different driver to bind on other models.
> > >
> >
> > Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> >
> > assuming it will go thru Input subsystem.
>
> I can take it, but I do not think it is dependent on the other change
> and thus can go through platform tree as well.

Pkease, take it. I do not expect any changes to the driver this cycle.
Dmitry Torokhov July 28, 2019, 9:57 a.m. UTC | #5
On Sat, Jul 27, 2019 at 03:26:41PM +0300, Andy Shevchenko wrote:
> On Sat, Jul 27, 2019 at 12:15 PM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> >
> > On Thu, Jul 25, 2019 at 08:57:53PM +0300, Andy Shevchenko wrote:
> > > On Sat, Jul 20, 2019 at 6:05 PM Maximilian Luz <luzmaximilian@gmail.com> wrote:
> > > >
> > > > Do not use the surfacepro3_button driver on newer Microsoft Surface
> > > > models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th
> > > > and possibly future generations) use the same device as the Surface Pro
> > > > 4 to represent their volume and power buttons (MSHW0040), but their
> > > > actual implementation is significantly different. This patch ensures
> > > > that the surfacepro3_button driver is only used on the Pro 3 and 4
> > > > models, allowing a different driver to bind on other models.
> > > >
> > >
> > > Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> > >
> > > assuming it will go thru Input subsystem.
> >
> > I can take it, but I do not think it is dependent on the other change
> > and thus can go through platform tree as well.
> 
> Pkease, take it. I do not expect any changes to the driver this cycle.

OK, applied, thank you.

Patch
diff mbox series

diff --git a/drivers/platform/x86/surfacepro3_button.c b/drivers/platform/x86/surfacepro3_button.c
index 47c6d000465a..ec515223f654 100644
--- a/drivers/platform/x86/surfacepro3_button.c
+++ b/drivers/platform/x86/surfacepro3_button.c
@@ -20,6 +20,12 @@ 
 #define SURFACE_BUTTON_OBJ_NAME		"VGBI"
 #define SURFACE_BUTTON_DEVICE_NAME	"Surface Pro 3/4 Buttons"
 
+#define MSHW0040_DSM_REVISION		0x01
+#define MSHW0040_DSM_GET_OMPR		0x02	// get OEM Platform Revision
+static const guid_t MSHW0040_DSM_UUID =
+	GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4, 0x95, 0xed, 0xab, 0x16, 0x65,
+		  0x49, 0x80, 0x35);
+
 #define SURFACE_BUTTON_NOTIFY_TABLET_MODE	0xc8
 
 #define SURFACE_BUTTON_NOTIFY_PRESS_POWER	0xc6
@@ -142,6 +148,44 @@  static int surface_button_resume(struct device *dev)
 }
 #endif
 
+/*
+ * Surface Pro 4 and Surface Book 2 / Surface Pro 2017 use the same device
+ * ID (MSHW0040) for the power/volume buttons. Make sure this is the right
+ * device by checking for the _DSM method and OEM Platform Revision.
+ *
+ * Returns true if the driver should bind to this device, i.e. the device is
+ * either MSWH0028 (Pro 3) or MSHW0040 on a Pro 4 or Book 1.
+ */
+static bool surface_button_check_MSHW0040(struct acpi_device *dev)
+{
+	acpi_handle handle = dev->handle;
+	union acpi_object *result;
+	u64 oem_platform_rev = 0;	// valid revisions are nonzero
+
+	// get OEM platform revision
+	result = acpi_evaluate_dsm_typed(handle, &MSHW0040_DSM_UUID,
+					 MSHW0040_DSM_REVISION,
+					 MSHW0040_DSM_GET_OMPR,
+					 NULL, ACPI_TYPE_INTEGER);
+
+	/*
+	 * If evaluating the _DSM fails, the method is not present. This means
+	 * that we have either MSHW0028 or MSHW0040 on Pro 4 or Book 1, so we
+	 * should use this driver. We use revision 0 indicating it is
+	 * unavailable.
+	 */
+
+	if (result) {
+		oem_platform_rev = result->integer.value;
+		ACPI_FREE(result);
+	}
+
+	dev_dbg(&dev->dev, "OEM Platform Revision %llu\n", oem_platform_rev);
+
+	return oem_platform_rev == 0;
+}
+
+
 static int surface_button_add(struct acpi_device *device)
 {
 	struct surface_button *button;
@@ -154,6 +198,9 @@  static int surface_button_add(struct acpi_device *device)
 	    strlen(SURFACE_BUTTON_OBJ_NAME)))
 		return -ENODEV;
 
+	if (!surface_button_check_MSHW0040(device))
+		return -ENODEV;
+
 	button = kzalloc(sizeof(struct surface_button), GFP_KERNEL);
 	if (!button)
 		return -ENOMEM;