linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver
@ 2021-01-27 16:25 mail
  2021-01-27 16:25 ` [PATCH v2 1/3] Outsourced sensor masks to PCI driver header mail
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mail @ 2021-01-27 16:25 UTC (permalink / raw)
  To: nehal-bakulchandra.shah, sandeep.singh, mail, jikos,
	benjamin.tissoires, arnd, linux-kernel, linux-input

From: Richard Neumann <mail@richard-neumann.de>

This patch adds quirks to the upstream (v8) version of the
AMD Sensor Fusion Hub driver.
The quirks provide a function to detect the sensor mask for systems
that do not have it stored in the AMD_P2C_MSG3 register.
The information about the systems IDs and available sensors was
taken from: https://bugzilla.kernel.org/show_bug.cgi?id=199715

Changes since v1:
* Added missing object amd_sfh_quirks.o to amd_sfh-objs
* changed type of "system" in "amd_sfh_quirks_get_sensor_mask"
  - struct dmi_system_id -> const struct dmi_system_id

Richard Neumann (3):
  Outsourced sensor masks to PCI driver header.
  Added quirks to detect sensor masks.
  Updated MAINTAINERS

 MAINTAINERS                              |  1 +
 drivers/hid/amd-sfh-hid/Makefile         |  1 +
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 16 +++----
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h   | 15 +++++++
 drivers/hid/amd-sfh-hid/amd_sfh_quirks.c | 55 ++++++++++++++++++++++++
 5 files changed, 79 insertions(+), 9 deletions(-)
 create mode 100644 drivers/hid/amd-sfh-hid/amd_sfh_quirks.c

-- 
2.30.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] Outsourced sensor masks to PCI driver header.
  2021-01-27 16:25 [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver mail
@ 2021-01-27 16:25 ` mail
  2021-01-27 16:25 ` [PATCH v2 2/3] Added quirks to detect sensor masks mail
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mail @ 2021-01-27 16:25 UTC (permalink / raw)
  To: nehal-bakulchandra.shah, sandeep.singh, mail, jikos,
	benjamin.tissoires, arnd, linux-kernel, linux-input

From: Richard Neumann <mail@richard-neumann.de>

Outsourced the mask definitions of the four sensors into
the PCI device driver header file for later use with the quirks.
Also renamed the values from *_EN to *_MASK to emphasize that
they are actually sensor bitmasks for matching against activestatus.

Signed-off-by: Richard Neumann <mail@richard-neumann.de>
---
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 13 ++++---------
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
index dbac16641662..4b0ceb2ee86a 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
@@ -20,11 +20,6 @@
 #define DRIVER_NAME	"pcie_mp2_amd"
 #define DRIVER_DESC	"AMD(R) PCIe MP2 Communication Driver"
 
-#define ACEL_EN		BIT(0)
-#define GYRO_EN		BIT(1)
-#define MAGNO_EN		BIT(2)
-#define ALS_EN		BIT(19)
-
 void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
 {
 	union sfh_cmd_param cmd_param;
@@ -79,16 +74,16 @@ int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id)
 
 	privdata->activecontrolstatus = readl(privdata->mmio + AMD_P2C_MSG3);
 	activestatus = privdata->activecontrolstatus >> 4;
-	if (ACEL_EN  & activestatus)
+	if (ACCEL_MASK  & activestatus)
 		sensor_id[num_of_sensors++] = accel_idx;
 
-	if (GYRO_EN & activestatus)
+	if (GYRO_MASK & activestatus)
 		sensor_id[num_of_sensors++] = gyro_idx;
 
-	if (MAGNO_EN & activestatus)
+	if (MAGNO_MASK & activestatus)
 		sensor_id[num_of_sensors++] = mag_idx;
 
-	if (ALS_EN & activestatus)
+	if (ALS_MASK & activestatus)
 		sensor_id[num_of_sensors++] = als_idx;
 
 	return num_of_sensors;
diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
index 8f8d19b2cfe5..a39f02352c3b 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
@@ -57,6 +57,20 @@ enum sensor_idx {
 	als_idx = 19
 };
 
+/**
+ * Bit masks for sensors matching.
+ * @ACCEL_MASK:	Bit mask of the accelerometer
+ * @GYRO_MASK:	Bit mask of the gyroscope
+ * @MAGNO_MASK:	Bit mask of the magnetometer
+ * @ALS_MASK:	Bit mask of the ambient light sensor
+ */
+enum sensor_mask {
+	ACCEL_MASK = BIT(accel_idx),
+	GYRO_MASK = BIT(gyro_idx),
+	MAGNO_MASK = BIT(mag_idx),
+	ALS_MASK = BIT(als_idx),
+};
+
 struct amd_mp2_dev {
 	struct pci_dev *pdev;
 	struct amdtp_cl_data *cl_data;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] Added quirks to detect sensor masks.
  2021-01-27 16:25 [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver mail
  2021-01-27 16:25 ` [PATCH v2 1/3] Outsourced sensor masks to PCI driver header mail
@ 2021-01-27 16:25 ` mail
  2021-01-27 16:26 ` [PATCH v2 3/3] Updated MAINTAINERS mail
  2021-02-09  9:39 ` [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver Jiri Kosina
  3 siblings, 0 replies; 5+ messages in thread
From: mail @ 2021-01-27 16:25 UTC (permalink / raw)
  To: nehal-bakulchandra.shah, sandeep.singh, mail, jikos,
	benjamin.tissoires, arnd, linux-kernel, linux-input

From: Richard Neumann <mail@richard-neumann.de>

Added quirks file to determine the sensor masks for systems
that do not have it stored in the corresponding P2C register.
Values are based upon user reports from:

    https://bugzilla.kernel.org/show_bug.cgi?id=199715

Signed-off-by: Richard Neumann <mail@richard-neumann.de>
---
 drivers/hid/amd-sfh-hid/Makefile         |  1 +
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   |  3 ++
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.h   |  1 +
 drivers/hid/amd-sfh-hid/amd_sfh_quirks.c | 55 ++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
 create mode 100644 drivers/hid/amd-sfh-hid/amd_sfh_quirks.c

diff --git a/drivers/hid/amd-sfh-hid/Makefile b/drivers/hid/amd-sfh-hid/Makefile
index 35e704da5612..c94cf51c0af5 100644
--- a/drivers/hid/amd-sfh-hid/Makefile
+++ b/drivers/hid/amd-sfh-hid/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_AMD_SFH_HID) += amd_sfh.o
 amd_sfh-objs := amd_sfh_hid.o
 amd_sfh-objs += amd_sfh_client.o
 amd_sfh-objs += amd_sfh_pcie.o
+amd_sfh-objs += amd_sfh_quirks.o
 amd_sfh-objs += hid_descriptor/amd_sfh_hid_desc.o
 
 ccflags-y += -I $(srctree)/$(src)/
diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
index 4b0ceb2ee86a..8f10d6d6b369 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
@@ -74,6 +74,9 @@ int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id)
 
 	privdata->activecontrolstatus = readl(privdata->mmio + AMD_P2C_MSG3);
 	activestatus = privdata->activecontrolstatus >> 4;
+	if (!activestatus)
+		activestatus = amd_sfh_quirks_get_sensor_mask(privdata->pdev);
+
 	if (ACCEL_MASK  & activestatus)
 		sensor_id[num_of_sensors++] = accel_idx;
 
diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
index a39f02352c3b..64884e515895 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h
@@ -90,4 +90,5 @@ void amd_stop_all_sensors(struct amd_mp2_dev *privdata);
 int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id);
 int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata);
 int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
+int amd_sfh_quirks_get_sensor_mask(struct pci_dev *pci_dev);
 #endif
diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_quirks.c b/drivers/hid/amd-sfh-hid/amd_sfh_quirks.c
new file mode 100644
index 000000000000..a4f0366e7982
--- /dev/null
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_quirks.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/*
+ * AMD Sensor Fusion Hub quirks
+ *
+ * Authors: Richard Neumann <mail@richard-neumann.de>
+ */
+
+#include <linux/dmi.h>
+#include <linux/pci.h>
+
+#include "amd_sfh_pcie.h"
+
+/**
+ * DMI match for HP ENVY x360 convertibles, which do not
+ * have information about the sensor mask in the P2C registers.
+ */
+static const struct dmi_system_id hp_envy_x360[] = {
+	{
+		.ident = "HP ENVY x360 Convertible 13-ag0xxx",
+		.matches = {
+			DMI_MATCH(DMI_PRODUCT_NAME, "HP"),
+			DMI_MATCH(DMI_BOARD_NAME, "8496"),
+			DMI_MATCH(DMI_BOARD_VERSION, "92.48"),
+		},
+	},
+	{
+		.ident = "HP ENVY x360 Convertible 15-cp0xxx",
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "HP"),
+			DMI_MATCH(DMI_BOARD_NAME, "8497"),
+			DMI_MATCH(DMI_BOARD_VERSION, "92.48"),
+		},
+	},
+	{ }
+};
+
+/**
+ * Returns the sensor mask for hardware, on which the
+ * sensor mask is not written into the P2C registers.
+ *
+ * Returns an appropriate sensor mask or zero per default.
+ */
+int amd_sfh_quirks_get_sensor_mask(struct pci_dev *pci_dev)
+{
+	const struct dmi_system_id *system;
+
+	system = dmi_first_match(hp_envy_x360);
+	if (system) {
+		pci_info(pci_dev, "Detected %s.\n", system->ident);
+		return ACCEL_MASK + MAGNO_MASK;
+	}
+
+	pci_warn(pci_dev, "No quirks available for this hardware.\n");
+	return 0;
+}
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] Updated MAINTAINERS
  2021-01-27 16:25 [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver mail
  2021-01-27 16:25 ` [PATCH v2 1/3] Outsourced sensor masks to PCI driver header mail
  2021-01-27 16:25 ` [PATCH v2 2/3] Added quirks to detect sensor masks mail
@ 2021-01-27 16:26 ` mail
  2021-02-09  9:39 ` [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver Jiri Kosina
  3 siblings, 0 replies; 5+ messages in thread
From: mail @ 2021-01-27 16:26 UTC (permalink / raw)
  To: nehal-bakulchandra.shah, sandeep.singh, mail, jikos,
	benjamin.tissoires, arnd, linux-kernel, linux-input

From: Richard Neumann <mail@richard-neumann.de>

Added Richard Neumann (me) to the list of maintainers for the
AMD Sensor Fusion Hub driver.

Signed-off-by: Richard Neumann <mail@richard-neumann.de>
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 992fe3b0900a..de28236a08fe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -958,6 +958,7 @@ F:	drivers/net/ethernet/amd/xgbe/
 AMD SENSOR FUSION HUB DRIVER
 M:	Nehal Shah <nehal-bakulchandra.shah@amd.com>
 M:	Sandeep Singh <sandeep.singh@amd.com>
+M:	Richard Neumann <mail@richard-neumann.de>
 L:	linux-input@vger.kernel.org
 S:	Maintained
 F:	Documentation/hid/amd-sfh*
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver
  2021-01-27 16:25 [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver mail
                   ` (2 preceding siblings ...)
  2021-01-27 16:26 ` [PATCH v2 3/3] Updated MAINTAINERS mail
@ 2021-02-09  9:39 ` Jiri Kosina
  3 siblings, 0 replies; 5+ messages in thread
From: Jiri Kosina @ 2021-02-09  9:39 UTC (permalink / raw)
  To: mail
  Cc: nehal-bakulchandra.shah, sandeep.singh, benjamin.tissoires, arnd,
	linux-kernel, linux-input

On Wed, 27 Jan 2021, mail@richard-neumann.de wrote:

> From: Richard Neumann <mail@richard-neumann.de>
> 
> This patch adds quirks to the upstream (v8) version of the
> AMD Sensor Fusion Hub driver.
> The quirks provide a function to detect the sensor mask for systems
> that do not have it stored in the AMD_P2C_MSG3 register.
> The information about the systems IDs and available sensors was
> taken from: https://bugzilla.kernel.org/show_bug.cgi?id=199715
> 
> Changes since v1:
> * Added missing object amd_sfh_quirks.o to amd_sfh-objs
> * changed type of "system" in "amd_sfh_quirks_get_sensor_mask"
>   - struct dmi_system_id -> const struct dmi_system_id

Nehal, Sandeep, can you please review this patchset? Thanks.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-09  9:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27 16:25 [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver mail
2021-01-27 16:25 ` [PATCH v2 1/3] Outsourced sensor masks to PCI driver header mail
2021-01-27 16:25 ` [PATCH v2 2/3] Added quirks to detect sensor masks mail
2021-01-27 16:26 ` [PATCH v2 3/3] Updated MAINTAINERS mail
2021-02-09  9:39 ` [PATCH v2 0/3] Add quirks to AMD Sensor Fusion Hub driver Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).