SFH: Add Support for AMD Sensor Fusion Hub
Subsystems (4)
v5 cover SFH: Add Support for AMD Sensor Fusion Hub
From: Sandeep Singh <[email protected]>
AMD SFH(Sensor Fusion Hub) is HID based driver.SFH FW is part of MP2 processor (MP2 which is an ARM® Cortex-M4 core based co-processor to x86) and it runs on MP2 where in driver resides on X86.The driver functionalities are divided into three parts:-
1: amd-mp2-pcie:- This module will communicate with MP2 FW and
provide that data into DRAM.
2: Client driver :- This part for driver will use dram data and
convert that data into HID format based on HID reports.
3: Transport driver :- This part of driver will communicate with
HID core. Communication between devices and HID core is mostly done via HID reports
In terms of architecture it is much more reassembles like ISH(Intel Integrated Sensor Hub). However the major difference is all the hid reports are generated as part of kernel driver. AMD SFH driver taken reference from ISH in terms of design and functionalities at fewer location.
AMD sensor fusion Hub is part of a SOC 17h family based platforms. The solution is working well on several OEM products. AMD SFH uses HID over PCIe bus.
Sandeep Singh (4):
SFH: Add maintainers and documentation for AMD SFH based on HID
framework
SFH: PCI driver to add support of AMD sensor fusion Hub using HID
framework
SFH: Transport Driver to add support of AMD Sensor Fusion Hub (SFH)
SFH: Create HID report to Enable support of AMD sensor fusion Hub
(SFH)
Changes since v1:
-Fix auto build test warnings
-Fix warnings captured using smatch
-Changes suggested by Dan Carpenter
Links of the review comments for v1:
[1] https://patchwork.kernel.org/patch/11325163/ [2] https://patchwork.kernel.org/patch/11325167/ [3] https://patchwork.kernel.org/patch/11325171/ [4] https://patchwork.kernel.org/patch/11325187/
Changes since v2:
-Debugfs divided into another patch
-Fix some cosmetic changes
-Fix for review comments
Reported and Suggested by:- Srinivas Pandruvada
Links of the review comments for v2:
[1] https://patchwork.kernel.org/patch/11355491/ [2] https://patchwork.kernel.org/patch/11355495/ [3] https://patchwork.kernel.org/patch/11355499/ [4] https://patchwork.kernel.org/patch/11355503/
Changes since v3:
-removed debugfs suggested by - Benjamin Tissoires
Links of the review comments for v3:
[1] https://lkml.org/lkml/2020/2/11/1256 [2] https://lkml.org/lkml/2020/2/11/1257 [3] https://lkml.org/lkml/2020/2/11/1258 [4] https://lkml.org/lkml/2020/2/11/1259 [5] https://lkml.org/lkml/2020/2/11/1260
Changes since v4:
- Rework done based on review comments by - Andy Shevchenko
- changes done based on suggested by -Richard Neumann
Links of the review comments for v4:
[1] https://lkml.org/lkml/2020/2/26/1360 [2] https://lkml.org/lkml/2020/2/26/1361 [3] https://lkml.org/lkml/2020/2/26/1362 [4] https://lkml.org/lkml/2020/2/26/1363 [5] https://lkml.org/lkml/2020/2/27/1
Sandeep Singh (4):
SFH: Add maintainers and documentation for AMD SFH based on HID
framework
SFH: PCI driver to add support of AMD sensor fusion Hub using HID
framework
SFH: Transport Driver to add support of AMD Sensor Fusion Hub (SFH
SFH: Create HID report to Enable support of AMD sensor fusion Hub
(SFH)
Documentation/hid/amd-sfh-hid.rst | 160 +++++ MAINTAINERS | 8 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 1 + drivers/hid/amd-sfh-hid/Kconfig | 21 + drivers/hid/amd-sfh-hid/Makefile | 16 + drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 196 +++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 137 +++++ drivers/hid/amd-sfh-hid/amdsfh-hid-client.c | 256 ++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 ++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 84 +++ .../hid_descriptor/amd_sfh_hid_descriptor.c | 251 ++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 14 files changed, 2078 insertions(+) create mode 100644 Documentation/hid/amd-sfh-hid.rst create mode 100644 drivers/hid/amd-sfh-hid/Kconfig create mode 100644 drivers/hid/amd-sfh-hid/Makefile create mode 100644 drivers/hid/amd-sfh-hid/amd_mp2_pcie.c create mode 100644 drivers/hid/amd-sfh-hid/amd_mp2_pcie.h create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid-client.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid.h create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.c create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.h create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_descriptor.h
Signature · 1 line
2.7.4
PATCH v5 1/4 SFH: Add maintainers and documentation for AMD SFH based on HID framework
From: Sandeep Singh <[email protected]>
Add Maintainers for AMD SFH(SENSOR FUSION HUB) Solution and work flow document.
--- Documentation/hid/amd-sfh-hid.rst | 160 ++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 8 ++ 2 files changed, 168 insertions(+) create mode 100644 Documentation/hid/amd-sfh-hid.rst
Documentation/hid/amd-sfh-hid.rst new file +160 -0
@@ -0,0 +1,160 @@ +.. SPDX-License-Identifier: GPL-2.0 + +AMD Sensor Fusion Hub:- +====================== +AMD Sensor Fusion Hub is part of a SOC starting from Ryzen based platforms. +The solution is working well on several OEM products. AMD +SFH uses HID over PCIe bus. In terms of architecture +it is much more resembles like ISH .However the major diffrence is all +The hid reports are generated as part of kernel driver. + +Block Diagram:- +============= + ------------------------------- + | HID User Space Applications | + ------------------------------- +--------------------------------------------- + --------------------------------- + | HID Core | + --------------------------------- + + --------------------------------- + | AMD HID Transport Driver | + --------------------------------- + + -------------------------------- + | AMD HID Client Driver | + | with HID Report Generator| + -------------------------------- + + -------------------------------- + | AMD MP2 PCIe Driver | + -------------------------------- +--------------------------------------------- + ------------------------------- + | SFH MP2 Processor | + -------------------------------- + + +AMD HID Transport Layer :- +*************************** +AMD SFH transport is also implemented as a bus. Each client application +executing in the AMD MP2 is registered as a device on this bus. +MP2 which is an ARM® Cortex-M4 core based co-processor to x86. +The driver, which binds each device (AMD SFH HID driver) identifies +the device type and registers with the hid core. Transport drivers +attach a constant "struct hid_ll_driver" object with each device. +Once a device is registered with HID core, the callbacks provided via +this struct are used by HID core to communicate with the device. +AMD HID Transport driver implements the synchronous calls. + +AMD HID Client Driver:- +********************** +This driver is responsible to implement HID request and descriptors. +As firmware is OS agnostic, HID client driver fills the HID request +structure and descriptors. HID client driver is in complex in nature +as it is interface between MP2 PCIe driver and HID. HID client driver +initialized the MP2 PCIe driver and holds the instance of MP2 driver. +It identified the number of sensors connected using MP2-PCIe driver and +based on that allocate the DRAM address for each and every sensor and +pass it to MP2-PCIe driver. +On enumeration of each sensor, client driver fills out the HID Descriptor +structure and HID input report structure. HID Feature report structure can +be optional. The report descriptor structure varies sensor to sensor. +Now on enumeration client driver does two major things +1. Register the HID sensor client to virtual bus (Platform driver) and bind it. +2. Probes the AMD HID transport driver. Which in turns register device to the core. + +AMD MP2 PCIe Driver:- +******************** +MP2 PCIe driver is responsible for making all transaction with the firmware over +PCIe.The connection establishment between firmware and MP2 PCIe driver happens here. + +The communication between X86 and MP2 is spilt into three parts. +1. Command Transfer => C2P Mailbox Register are used +2. Data Transfer => DRAM + +Commands are sent to MP2 using C2P Mail Box registers. These C2P registers +are common between x86 and MP2. Writing into C2P Message register generate +interrupt to MP2. The client driver allocates the physical memory and send +the same to MP2 for data transfer. MP2 firmware uses HUBIF interface +to access DRAM memory. For Firmware always write minimum 32 bytes +into DRAM.So it is expected that driver shall allocate minimum 32 bytes DRAM space. + +Enumeration and Probing flow:- +***************************** + HID AMD AMD AMD -PCIe MP2 + Core Transport Client Driver Driver FW + | | | | | + | | on Boot Driver Loaded | | + | | | | | + | | |----MP2-PCIe Int---------> | | + | | | | | + | | |---Get Number of sensors-> | | + | | | Read P2C | + | | | Register | + | | | | | + | | | Loop(for No of Sensors) | | + | | |----------------------| | | + | | | Create HID Descriptor| | | + | | | Create Input report | | | + | | | Descriptor Map | | | + | | | the MP2 FW Index to | | | + | | | HID Index | | | + | | | Allocate the DRAM | Enable | + | | | address | Sensors | + | | |----------------------| | | + | | HID transport| | Enable | + | |<--Probe------| |---Sensor CMD--> | + | | Create the | | | + | | HID device | | | + | | (MFD) | | | + | | by Populating| | | + | | the HID | | | + | | ll_driver | | | + | HID | | | | + | add | | | | + |Device | | | | + |<------------- | | | | + + +Data Flow from Application to the AMD SFH Driver:- +************************************************* + + | | | | | +Get | | | | | +Input | | | | | +Report | | | | | +---> | | | | | + |HID_req | | | | + |get_report | | | | + |------------->| | | | + | | HID_get_input| | | + | | report | | | + | |------------->|------------------------| | | + | | | Read the DRAM data for| | | + | | | requsted sensor and | | | + | | | create the HID input | | | + | | | report | | | + | | |------------------------| | | + | |Data received | | | + | | in HID report| | | + To |<-------------|<-------------| | | +Applications | | | | +<-------| | | | | + + +Data Flow from AMD SFH Driver to Application:- +********************************************** + | | | | | + | | |------------------------| | | + | | |Periodically Read | | | + | | |the data for all | | | + | | |enumerated sensors | | | + | | |from the dram and create| | | + | | | HID Input reports | | | + | | |------------------------| | | + | |HID Input | | | + | |Input report | | | + <----submit to Application-----| | | + | | | | |
MAINTAINERS +8 -0
@@ -884,6 +884,14 @@ S: Supported F: drivers/net/ethernet/amd/xgbe/ F: arch/arm64/boot/dts/amd/amd-seattle-xgbe*.dtsi +AMD SENSOR FUSION HUB DRIVER +M: Nehal Shah <[email protected]> +M: Sandeep Singh <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/hid/amd-sfh* +F: drivers/hid/amd-sfh-hid/ + ANALOG DEVICES INC AD5686 DRIVER M: Stefan Popa <[email protected]> L: [email protected]
Signature · 1 line
2.7.4
PATCH v5 2/4 SFH: PCI driver to add support of AMD sensor fusion Hub using HID framework
In reply to Sandeep SinghFrom: Sandeep Singh <[email protected]>
AMD SFH uses HID over PCIe bus.SFH fw is part of MP2 processor (MP2 which is an ARM® Cortex-M4 core based co-processor to x86) and it runs on MP2 where in driver resides on X86. This part of module will communicate with MP2 FW and provide that data into DRAM
--- drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 1 + drivers/hid/amd-sfh-hid/Kconfig | 21 ++++ drivers/hid/amd-sfh-hid/Makefile | 16 +++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 196 +++++++++++++++++++++++++++++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 137 +++++++++++++++++++++++ 6 files changed, 373 insertions(+) create mode 100644 drivers/hid/amd-sfh-hid/Kconfig create mode 100644 drivers/hid/amd-sfh-hid/Makefile create mode 100644 drivers/hid/amd-sfh-hid/amd_mp2_pcie.c create mode 100644 drivers/hid/amd-sfh-hid/amd_mp2_pcie.h
drivers/hid/Kconfig +2 -0
@@ -1155,4 +1155,6 @@ source "drivers/hid/i2c-hid/Kconfig" source "drivers/hid/intel-ish-hid/Kconfig" +source "drivers/hid/amd-sfh-hid/Kconfig" + endmenu
drivers/hid/Makefile +1 -0
@@ -139,3 +139,4 @@ obj-$(CONFIG_I2C_HID) += i2c-hid/ obj-$(CONFIG_INTEL_ISH_HID) += intel-ish-hid/ obj-$(INTEL_ISH_FIRMWARE_DOWNLOADER) += intel-ish-hid/ +obj-$(CONFIG_AMD_SFH_HID) += amd-sfh-hid/
drivers/hid/amd-sfh-hid/Kconfig new file +21 -0
@@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-only +menu "AMD SFH HID support" + depends on X86_64 || COMPILE_TEST + depends on PCI + +config AMD_SFH_HID + tristate "AMD Sensor Fusion Hub" + select HID + help + If you say yes to this option, support will be included for the AMD + Sensor Fusion Hub. + This driver will enable sensors functionality to user through HID + framework. Basically this driver will get data from MP2 FW + and provide that data to HID framework. + MP2 which is an ARM® Cortex-M4 core based co-processor to x86. + + This driver can also be built as modules. If so, the modules will + be called amd-mp2-pcie and amd-sfhtp-hid. + Say Y or M here if you want to support AMD SFH. If unsure, say N. + +endmenu
drivers/hid/amd-sfh-hid/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile - AMD SFH HID drivers +# Copyright (c) 2020-2021, Advanced Micro Devices, Inc. +# + +ccflags-m := -Werror +obj-$(CONFIG_AMD_SFH_HID) += amd-mp2-pcie.o +amd-mp2-pcie-objs := amd_mp2_pcie.o + +obj-$(CONFIG_AMD_SFH_HID) +=amd-sfhtp-hid.o +amd-sfhtp-hid-objs := amdsfh-hid.o +amd-sfhtp-hid-objs+= amdsfh-hid-client.o +amd-sfhtp-hid-objs+= hid_descriptor/amd_sfh_hid_descriptor.o + +ccflags-y += -I$(srctree)/$(src)/
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +196 -0
196 lines not on this page · raw message
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v5 2/4] SFH: PCI driver to add support of AMD sensor fusion Hub using HID framework
Quoted 9 lines · Sandeep Singh
From: Sandeep Singh <[email protected]>
AMD SFH uses HID over PCIe bus.SFH fw is part of MP2 processor (MP2 which is an ARM® Cortex-M4 core based co-processor to x86) and it runs on MP2 where in driver resides on X86. This part of module will communicate with MP2 FW and provide that data into DRAM
Quoted 3 lines
Signed-off-by Sandeep Singh <[email protected]>Signed-off-by Nehal Shah <[email protected]>
Why you are submitting code if Nehal's SoB last in the list?
...
Quoted 1 line
Reported-by kbuild test robot <[email protected]>
I guess it's not applicable here, since it's a new code. Rather you may mentioned this in changelog in cover letter.
...
Quoted 1 line
+
write64(0x0, privdata->mmio + AMD_C2P_MSG2);
Hmm... What's write64()? Isn't it writeq()?
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 97
Quoted 4 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +4
-0+if (ACEL_EN & activestatus) { + sensor_id[num_of_sensors] =ACCEL_IDX ; + num_of_sensors++; + }
You can drop a lot of LOCs by doing
if (ACEL_EN & activestatus)
sensor_id[num_of_sensors++] = ACCEL_IDX;
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 128
Quoted 4 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +3
-0+ rc =pcim_iomap_regions (pdev,BIT (2 ),DRIVER_NAME ); +if (rc) + goto err_pci_enable;
Due to use of PCI managed functions error path is not needed at all. Return directly.
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 138
Quoted 6 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +6
-0+ rc =pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )); +if (rc) { + rc =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )); +if (rc) + goto err_dma_mask; + }
rc = ...;
if (rc)
rc = ...;
if (rc)
return rc;
...
Review
Quoted 2 lines
(quoted diff) +2
-0+err_dma_mask: + pci_clear_master(pdev);
PCI managed handling does it for you.
Review
Quoted 2 lines
(quoted diff) +2
-0+err_pci_enable: + pci_set_drvdata(pdev, NULL);
Driver code does this for you.
Quoted 1 line
+ return rc;
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 156
Quoted 2 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +2
-0+dev_info (&pdev->dev,"MP2 device found [%04x:%04x] (rev %x)\n" , + pdev->vendor, pdev->device, pdev->revision);
How is it useful? PCI core prints a lot of information which you may find in dmesg.
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 160
Quoted 4 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +3
-0+ privdata =devm_kzalloc (&pdev->dev,sizeof (*privdata),GFP_KERNEL ); +if (!privdata) + rc = -ENOMEM ;
How this has been tested?
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 166
Quoted 6 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +5
-0+ privdata->pdev = pdev; + rc =amd_mp2_pci_init (privdata, pdev); +if (rc) +return rc; +return 0 ;
return amd_mp2_pci_init(...);
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 175
Quoted 8 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +7
-0+static void amd_mp2_pci_remove (struct pci_dev *pdev) +{ +struct amd_mp2_dev *privdata =pci_get_drvdata (pdev); + +amd_stop_all_sensors (privdata->pdev); +pci_clear_master (pdev); +pci_set_drvdata (pdev,NULL );
Same comments as per error path in the ->probe()
Quoted 1 line
+}
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c line 179
Quoted 2 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.c new file +2
-0+static const struct pci_device_id amd_mp2_pci_tbl[] = { + {PCI_VDEVICE (AMD ,PCI_DEVICE_ID_AMD_MP2 )},
Spaces, please,
{ PCI...() },
Quoted 1 line
+ {0}
0 is not needed here.
Quoted 1 line
+};
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h line 10
Quoted 2 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h new file +2
-0+#ifndef PCIE_MP2_AMD_H +#define PCIE_MP2_AMD_H
+ empty line
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h line 14
Quoted 5 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h new file +4
-0+#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/pci.h> +#include <linux/types.h> +#define PCI_DEVICE_ID_AMD_MP2 0x15E4
Why not in the C file?
Quoted 9 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h new file +9
-0+/* MP2 C2P Message Registers */ +#define AMD_C2P_MSG0 0x10500 +#define AMD_C2P_MSG1 0x10504 +#define AMD_C2P_MSG2 0x10508 +#define AMD_C2P_MSG3 0x1050c +#define AMD_C2P_MSG4 0x10510 +#define AMD_C2P_MSG5 0x10514 +#define AMD_C2P_MSG6 0x10518 +#define AMD_C2P_MSG7 0x1051c
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h line 34
Quoted 10 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h new file +10
-0+#define AMD_C2P_MSG8 0x10520 +#define AMD_C2P_MSG9 0x10524 + +/* MP2 P2C Message Registers */ +#define AMD_P2C_MSG0 0x10680/*Do not use*/ +#define AMD_P2C_MSG1 0x10684 +#define AMD_P2C_MSG2 0x10688 +#define AMD_P2C_MSG3 0x1068C/*MP2 debug info*/ +#define AMD_P2C_MSG_INTEN 0x10690/*MP2 int gen register*/ +#define AMD_P2C_MSG_INTSTS 0x10694/*Interrupt sts*/
Do you need all these in the header?
...
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h line 37
Quoted 2 lines
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h new file +2
-0+#define write64 lo_hi_writeq +#define read64 lo_hi_readq
Why?! You have writeq() definition or use lo_hi_*() directly.
...
Quoted 1 line
+int
amd_mp2_get_sensor_num(struct pci_dev *dev, u8 *sensor_id);
+ blank line
Quoted 1 line
+#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v5 3/4 SFH: Transport Driver to add support of AMD Sensor Fusion Hub (SFH
In reply to Sandeep SinghFrom: Sandeep Singh <[email protected]>
This part of module will provide the interaction between HID framework and client driver.This modules will registered client driver with HID framework.
--- drivers/hid/amd-sfh-hid/amdsfh-hid-client.c | 256 ++++++++++++++++++++++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 +++++++++++++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 84 +++++++++ 3 files changed, 519 insertions(+) create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid-client.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid.h
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +256 -0
@@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* AMD SFH Client Driver +* Author: Nehal Bakulchandra Shah <[email protected]> +*/ + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/workqueue.h> +#include <linux/hid.h> +#include <linux/list.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> +#include <linux/dma-mapping.h> +#include "amdsfh-hid.h" +#include "amd_mp2_pcie.h" +#include "hid_descriptor/amd_sfh_hid_descriptor.h" + +#define DRIVER_DESC "AMD(R) PCIe MP2 Communication Client Driver" +#define DRIVER_NAME "AMD_SFH_HID_CLIENT" +#define PERIOD 200 + +struct request_list { +struct hid_device *hid; +struct list_head list; +u8 report_id; +u8 sensor_idx; +u8 report_type; +u8 current_index; +}; + +static struct request_list req_list; +static struct amdtp_cl_data *cl_data_context; + +void amd_sfh_set_report (struct hid_device *hid,int report_id, +int report_type) +{ +struct amdtp_hid_data *hid_data = hid->driver_data; +struct amdtp_cl_data *cli_data = hid_data->cli_data; +int i; + +for (i =0 ; i < cli_data->num_hid_devices; i++) { +if (cli_data->hid_sensor_hubs[i] == hid) { + cli_data->cur_hid_dev = i; +break ; + } + } +amdtp_hid_wakeup (hid); +} +EXPORT_SYMBOL (amd_sfh_set_report); + +void amd_sfh_get_report (struct hid_device *hid,int report_id, +int report_type) +{ +struct amdtp_hid_data *hid_data = hid->driver_data; +struct amdtp_cl_data *cli_data = hid_data->cli_data; +int i; + +for (i =0 ; i < cli_data->num_hid_devices; i++) { +if (cli_data->hid_sensor_hubs[i] == hid) { +struct request_list *new_request =kzalloc + (sizeof (*new_request),GFP_KERNEL ); + new_request->current_index = i; + new_request->sensor_idx = cli_data->sensor_idx[i]; + new_request->hid = hid; + new_request->report_type = report_type; + new_request->report_id = report_id; + cli_data->report_id[i] = report_id; + cli_data->request_done[i] = false; +list_add (&new_request->list, &req_list.list); +break ; + } + } +schedule_delayed_work (&cli_data->work,0 ); +} +EXPORT_SYMBOL (amd_sfh_get_report); + +static void amd_sfh_work (struct work_struct *work) +{ +struct amdtp_cl_data *cli_data =amd_sfh_cldata (work); +struct request_list *req_node; +u8 report_size =0 ; +u8 current_index; +u8 sensor_index; +u8 report_id; +u8 node_type; + + req_node = list_last_entry(&req_list.list, struct request_list, list); +list_del (&req_node->list); + current_index = req_node->current_index; + sensor_index = req_node->current_index; + report_id = req_node->report_id; + node_type = req_node->report_type; + +if (node_type ==HID_FEATURE_REPORT ) { + report_size =get_feature_report (sensor_index, report_id, + cli_data->feature_report + [current_index]); + }else if (node_type ==HID_INPUT_REPORT ) { + report_size =get_input_report (sensor_index, report_id, + cli_data->input_report + [current_index], + cli_data->sensor_virt_addr + [current_index]); + } + +hid_input_report (cli_data->hid_sensor_hubs[current_index], + cli_data->report_type[current_index], + cli_data->input_report[current_index], + report_size,0 ); + cli_data->cur_hid_dev = current_index; + cli_data->sensor_requested_cnt[current_index] =0 ; +amdtp_hid_wakeup (cli_data->hid_sensor_hubs[current_index]); +} + +static void amd_sfh_work_buffer (struct work_struct *work) +{ +struct amdtp_cl_data *cli_data = cl_data_context; +unsigned int i; +u8 report_size =0 ; + +for (i =0 ; i < cli_data->num_hid_devices; i++) { + report_size =get_input_report (cli_data->sensor_idx[i], + cli_data->report_id[i], + cli_data->input_report[i], + cli_data->sensor_virt_addr[i]); +hid_input_report (cli_data->hid_sensor_hubs[i], +HID_INPUT_REPORT , + cli_data->input_report[i], report_size,0 ); + } + +schedule_delayed_work (&cli_data->work_buffer,PERIOD ); +} + +static int amd_sfh_hid_client_probe (struct platform_device *pdev) +{ +struct amd_mp2_sensor_info info; +int rc =0 ; +int i; +struct amdtp_cl_device *cl_dev; +struct amdtp_cl_data *cl_data; +u32 feature_report_size =0 ; +u32 input_report_size =0 ; + + cl_dev =devm_kzalloc (&pdev->dev,sizeof (*cl_dev),GFP_KERNEL ); +if (!cl_dev) +return -ENOMEM ; + + cl_dev->pdev =pci_get_device (PCI_VENDOR_ID_AMD , +PCI_DEVICE_ID_AMD_MP2 ,NULL ); +if (!cl_dev->pdev) +return -ENOMEM ; + + cl_data =kzalloc (sizeof (*cl_data),GFP_KERNEL ); + cl_data->num_hid_devices =amd_mp2_get_sensor_num + (cl_dev->pdev, &cl_data->sensor_idx[0 ]); + +INIT_DELAYED_WORK (&cl_data->work, amd_sfh_work); +INIT_DELAYED_WORK (&cl_data->work_buffer, amd_sfh_work_buffer); +INIT_LIST_HEAD (&req_list.list); + +for (i =0 ; i < cl_data->num_hid_devices; i++) { + cl_data->sensor_virt_addr[i] =dma_alloc_coherent + (&cl_dev->pdev->dev,sizeof (int ) *8 , + &cl_data->sensor_phy_addr[i],GFP_KERNEL ); + cl_data->sensor_sts[i] =0 ; + cl_data->sensor_requested_cnt[i] =0 ; + cl_data->cur_hid_dev = i; + + cl_data->report_descr_size[i] =get_descriptor_size + (cl_data->sensor_idx[i], descr_size); + + feature_report_size =get_descriptor_size + (cl_data->sensor_idx[i], feature_size); + + input_report_size =get_descriptor_size + (cl_data->sensor_idx[i], input_size); + + cl_data->feature_report[i] =kzalloc (feature_report_size, +GFP_KERNEL ); + cl_data->input_report[i] =kzalloc (input_report_size, +GFP_KERNEL ); + info.period =PERIOD ; + info.sensor_idx = cl_data->sensor_idx[i]; + info.phy_address = cl_data->sensor_phy_addr[i]; + cl_data->report_descr[i] =kzalloc + (cl_data->report_descr_size[i],GFP_KERNEL ); +if (!cl_data->report_descr[i]) +return -ENOMEM ; + rc =get_report_descriptor (cl_data->sensor_idx[i], + cl_data->report_descr[i]); + rc =amdtp_hid_probe (cl_data->cur_hid_dev, cl_data); +amd_start_sensor (cl_dev->pdev, info); + cl_data->sensor_sts[i] =1 ; + } + + cl_dev->cl_data = cl_data; + cl_data_context = cl_data; +platform_set_drvdata (pdev, cl_dev); +schedule_delayed_work (&cl_data->work_buffer,PERIOD ); +return 0 ; +} + +static int amd_sfh_hid_client_remove (struct platform_device *pdev) +{ +int i; +struct amdtp_cl_device *cl_dev; +struct amdtp_cl_data *cl_data; + + cl_dev =platform_get_drvdata (pdev); +if (!(cl_dev)) +return -EINVAL ; + + cl_data = cl_dev->cl_data; +if (!(cl_data)) +return -EINVAL ; + +for (i =0 ; i < cl_data->num_hid_devices; i++) +amd_stop_sensor (cl_dev->pdev, i); + +cancel_delayed_work_sync (&cl_data->work); +cancel_delayed_work_sync (&cl_data->work_buffer); +amdtp_hid_remove (cl_data); + +for (i =0 ; i < cl_data->num_hid_devices; i++) { +if (cl_data->sensor_virt_addr[i]) +dma_free_coherent (&cl_dev->pdev->dev,8 *sizeof (int ), + cl_data->sensor_virt_addr[i], + cl_data->sensor_phy_addr[i]); + } + +kfree (cl_data); +pr_info ("%s:%s Exit\n" ,DRIVER_NAME , __func__); +return 0 ; +} + +static const struct acpi_device_id amd_sfh_acpi_match[] = { { +"AMDI0080" }, + { }, +}; + +MODULE_DEVICE_TABLE (acpi, amd_sfh_acpi_match); +static struct platform_driver amd_sfh_plat_driver = { + .probe = amd_sfh_hid_client_probe, + .remove = amd_sfh_hid_client_remove, + .driver = { + .name ="amd_sfh_platform" , + .acpi_match_table =ACPI_PTR (amd_sfh_acpi_match), + }, +}; +module_platform_driver (amd_sfh_plat_driver); +MODULE_DESCRIPTION ("AMD(R) SFH Client Driver" ); +MODULE_AUTHOR ("Nehal Shah <[email protected]>" ); +MODULE_LICENSE ("Dual BSD/GPL" );
drivers/hid/amd-sfh-hid/amdsfh-hid.c new file +179 -0
179 lines not on this page · raw message
drivers/hid/amd-sfh-hid/amdsfh-hid.h new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v5 3/4] SFH: Transport Driver to add support of AMD Sensor Fusion Hub (SFH
Quoted 6 lines · Sandeep Singh
From: Sandeep Singh <[email protected]>
This part of module will provide the interaction between HID framework and client driver.This modules will registered client driver with HID framework.
...
Quoted 2 lines
Signed-off-by Sandeep Singh <[email protected]>Signed-off-by Nehal Shah <[email protected]>
Use proper sequence and Co-developed-by if applicable.
Quoted 2 lines
Reported-by kbuild test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>
What has been reported? Absence of the drivers?
...
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 16
Quoted 10 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +10
-0+#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/workqueue.h> +#include <linux/hid.h> +#include <linux/list.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> +#include <linux/dma-mapping.h>
Keep ordered?
Quoted 3 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +3
-0+#include "amdsfh-hid.h" +#include "amd_mp2_pcie.h" +#include "hid_descriptor/amd_sfh_hid_descriptor.h"
...
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 64
Quoted 12 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +11
-0+void amd_sfh_get_report (struct hid_device *hid,int report_id, +int report_type) +{ +struct amdtp_hid_data *hid_data = hid->driver_data; +struct amdtp_cl_data *cli_data = hid_data->cli_data; +int i; + +for (i =0 ; i < cli_data->num_hid_devices; i++) { +if (cli_data->hid_sensor_hubs[i] == hid) { +struct request_list *new_request =kzalloc + (sizeof (*new_request),GFP_KERNEL );
Bad indentation.
Quoted 1 line
+
new_request->current_index= i;
Huh? NULL pointer dereference!
Quoted 13 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +13
-0+ new_request->sensor_idx = cli_data->sensor_idx[i]; + new_request->hid = hid; + new_request->report_type = report_type; + new_request->report_id = report_id; + cli_data->report_id[i] = report_id; + cli_data->request_done[i] = false; +list_add (&new_request->list, &req_list.list); +break ; + } + } +schedule_delayed_work (&cli_data->work,0 ); +} +EXPORT_SYMBOL (amd_sfh_get_report);
...
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 122
Quoted 6 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +5
-0+static void amd_sfh_work_buffer (struct work_struct *work) +{ +struct amdtp_cl_data *cli_data = cl_data_context; +unsigned int i; +u8 report_size =0 ;
Redundant assignment.
Quoted 12 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +12
-0+for (i =0 ; i < cli_data->num_hid_devices; i++) { + report_size =get_input_report (cli_data->sensor_idx[i], + cli_data->report_id[i], + cli_data->input_report[i], + cli_data->sensor_virt_addr[i]); +hid_input_report (cli_data->hid_sensor_hubs[i], +HID_INPUT_REPORT , + cli_data->input_report[i], report_size,0 ); + } + +schedule_delayed_work (&cli_data->work_buffer,PERIOD ); +}
...
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 145
Quoted 9 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +9
-0+static int amd_sfh_hid_client_probe (struct platform_device *pdev) +{ +struct amd_mp2_sensor_info info; +int rc =0 ; +int i; +struct amdtp_cl_device *cl_dev; +struct amdtp_cl_data *cl_data; +u32 feature_report_size =0 ; +u32 input_report_size =0 ;
Are you sure all those assignments are needed?
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 152
Quoted 2 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +2
-0+ cl_dev->pdev =pci_get_device (PCI_VENDOR_ID_AMD , +PCI_DEVICE_ID_AMD_MP2 ,NULL );
I'm not quite sure you understand what you are doing here. The code below is full of leak.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 154
Quoted 3 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +2
-0+if (!cl_dev->pdev) +return -ENOMEM ;
What?
...
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 158
Quoted 4 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +3
-0+ cl_data =kzalloc (sizeof (*cl_data),GFP_KERNEL ); + cl_data->num_hid_devices =amd_mp2_get_sensor_num + (cl_dev->pdev, &cl_data->sensor_idx[0 ]);
Strange indentation.
NULL pointer dereference!
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 167
Quoted 5 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +4
-0+for (i =0 ; i < cl_data->num_hid_devices; i++) { + cl_data->sensor_virt_addr[i] =dma_alloc_coherent + (&cl_dev->pdev->dev,sizeof (int ) *8 , + &cl_data->sensor_phy_addr[i],GFP_KERNEL );
Indentation.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 179
Quoted 8 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +8
-0+ cl_data->report_descr_size[i] =get_descriptor_size + (cl_data->sensor_idx[i], descr_size); + + feature_report_size =get_descriptor_size + (cl_data->sensor_idx[i], feature_size); + + input_report_size =get_descriptor_size + (cl_data->sensor_idx[i], input_size);
Ditto.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 184
Quoted 4 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +4
-0+ cl_data->feature_report[i] =kzalloc (feature_report_size, +GFP_KERNEL ); + cl_data->input_report[i] =kzalloc (input_report_size, +GFP_KERNEL );
NULL pointer dereference.
You probably need to understand how memory allocation and heap usage works.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 189
Quoted 6 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +5
-0+ info.period =PERIOD ; + info.sensor_idx = cl_data->sensor_idx[i]; + info.phy_address = cl_data->sensor_phy_addr[i]; + cl_data->report_descr[i] =kzalloc + (cl_data->report_descr_size[i],GFP_KERNEL );
Indentation.
Quoted 15 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +15
-0+if (!cl_data->report_descr[i]) +return -ENOMEM ; + rc =get_report_descriptor (cl_data->sensor_idx[i], + cl_data->report_descr[i]); + rc =amdtp_hid_probe (cl_data->cur_hid_dev, cl_data); +amd_start_sensor (cl_dev->pdev, info); + cl_data->sensor_sts[i] =1 ; + } + + cl_dev->cl_data = cl_data; + cl_data_context = cl_data; +platform_set_drvdata (pdev, cl_dev); +schedule_delayed_work (&cl_data->work_buffer,PERIOD ); +return 0 ; +}
...
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 210
Quoted 5 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +5
-0+static int amd_sfh_hid_client_remove (struct platform_device *pdev) +{ +int i; +struct amdtp_cl_device *cl_dev; +struct amdtp_cl_data *cl_data;
Reversed xmas tree, please.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 214
Quoted 4 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +3
-0+ cl_dev =platform_get_drvdata (pdev); +if (!(cl_dev)) +return -EINVAL ;
When this will be true?!
This can be done directly in the definition block above.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 218
Quoted 4 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +3
-0+ cl_data = cl_dev->cl_data; +if (!(cl_data)) +return -EINVAL ;
Ditto.
Quoted 6 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +6
-0+for (i =0 ; i < cl_data->num_hid_devices; i++) +amd_stop_sensor (cl_dev->pdev, i); + +cancel_delayed_work_sync (&cl_data->work); +cancel_delayed_work_sync (&cl_data->work_buffer); +amdtp_hid_remove (cl_data);
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 234
Quoted 10 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +9
-0+ +for (i =0 ; i < cl_data->num_hid_devices; i++) { +if (cl_data->sensor_virt_addr[i]) +dma_free_coherent (&cl_dev->pdev->dev,8 *sizeof (int ), + cl_data->sensor_virt_addr[i], + cl_data->sensor_phy_addr[i]); + } + +kfree (cl_data);
Why not devm in the probe and nothing here?
Quoted 1 line
+
pr_info("%s:%s Exit\n", DRIVER_NAME, __func__);
No, no. Remove this noise.
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
...
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 241
Quoted 4 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +3
-0+static const struct acpi_device_id amd_sfh_acpi_match[] = { { +"AMDI0080" }, + { },
No comma on terminators.
Quoted 1 line
+};
Indentation is horrible. You have to look into existing drivers (better newer ones) to see how to have done things like this.
Quoted 1 line
+
Blank line in wrong place...
Quoted 1 line
+MODULE_DEVICE_TABLE(acpi,
amd_sfh_acpi_match);
...should be here.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 250
Quoted 7 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +6
-0+static struct platform_driver amd_sfh_plat_driver = { + .probe = amd_sfh_hid_client_probe, + .remove = amd_sfh_hid_client_remove, + .driver = { + .name ="amd_sfh_platform" , + .acpi_match_table =ACPI_PTR (amd_sfh_acpi_match),
ACPI_PTR() is redundant and/or provokes compilation warnings.
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c line 253
Quoted 3 lines
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c new file +3
-0+ }, +}; +module_platform_driver (amd_sfh_plat_driver);
+ blank line.
...
drivers/hid/amd-sfh-hid/amdsfh-hid.c line 33
Quoted 12 lines
drivers/hid/amd-sfh-hid/amdsfh-hid.c new file +11
-0+static int amdtp_hid_parse (struct hid_device *hid) +{ +struct amdtp_hid_data *hid_data = hid->driver_data; +struct amdtp_cl_data *cli_data = hid_data->cli_data; +int rc; + + rc =hid_parse_report (hid, cli_data->report_descr[hid_data->index], + cli_data->report_descr_size[hid_data->index]); +if (rc) +return rc; +return 0 ;
return hid_parse_report(...);
Quoted 1 line
+}
...
drivers/hid/amd-sfh-hid/amdsfh-hid.c line 72
Quoted 11 lines
drivers/hid/amd-sfh-hid/amdsfh-hid.c new file +11
-0+static void amdtp_hid_request (struct hid_device *hid,struct hid_report *rep, +int reqtype) +{ +switch (reqtype) { +case HID_REQ_GET_REPORT : +amd_sfh_get_report (hid, rep->id, rep->type); +break ; +case HID_REQ_SET_REPORT : +amd_sfh_set_report (hid, rep->id, reqtype); +break ; + }
default?
Quoted 1 line
+}
...
Quoted 6 lines
drivers/hid/amd-sfh-hid/amdsfh-hid.c new file +6
-0+static int amdtp_wait_for_response (struct hid_device *hid) +{ +struct amdtp_hid_data *hid_data = hid->driver_data; +struct amdtp_cl_data *cli_data = hid_data->cli_data; +int i =0 ; +
drivers/hid/amd-sfh-hid/amdsfh-hid.c line 89
Quoted 10 lines
drivers/hid/amd-sfh-hid/amdsfh-hid.c new file +9
-0+for (i =0 ; i < cli_data->num_hid_devices; i++) { +if (cli_data->hid_sensor_hubs[i] == hid) +break ; + } +if (!cli_data->request_done[i]) +wait_event_interruptible_timeout (hid_data->hid_wait, + cli_data->request_done[i], +1500 ); +if (!cli_data->request_done[i]) {
Shouldn't you rather check returned value from previous call?
Quoted 8 lines
drivers/hid/amd-sfh-hid/amdsfh-hid.c new file +8
-0+hid_err (hid, +"timeout waiting for response from device\n" ); +return -ETIMEDOUT ; + } + cli_data->request_done[i] = false; + +return 0 ; +}
...
drivers/hid/amd-sfh-hid/amdsfh-hid.c line 129
Quoted 5 lines
drivers/hid/amd-sfh-hid/amdsfh-hid.c new file +4
-0+ hid =hid_allocate_device (); +if (IS_ERR (hid)) { + rc =PTR_ERR (hid); +return -ENOMEM ;
Huh?!
Quoted 1 line
+ }
...
drivers/hid/amd-sfh-hid/amdsfh-hid.h line 11
Quoted 4 lines
drivers/hid/amd-sfh-hid/amdsfh-hid.h new file +3
-0+#ifndef AMDSFH_HID_H +#define AMDSFH_HID_H +#include <linux/debugfs.h>
What?! I see useds of other stuff, but this...
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v5 4/4 SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)
In reply to Sandeep SinghFrom: Sandeep Singh <[email protected]>
This part of module will define the data into HID reports. Get data from PCIe driver and populate that data into reports. HID core communication between devices and HID core is mostly done via HID reports.
--- .../hid_descriptor/amd_sfh_hid_descriptor.c | 251 ++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 3 files changed, 1018 insertions(+) create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.c create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.h create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_descriptor.h
drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.c new file +251 -0
@@ -0,0 +1,251 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* AMD SFH Report Descriptor generator logic +* Author: Nehal Bakulchandra Shah <[email protected]> +*/ + +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/slab.h> +#include "amd_sfh_hid_descriptor.h" +#include "amd_sfh_hid_report_descriptor.h" +#include "amd_mp2_pcie.h" + +#define AMD_SFH_FIRMWARE_MULTIPLIER (1000) +#define HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM 0x41 +#define HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM 0x51 +#define HID_DEFAULT_REPORT_INTERVAL 0x50 +#define HID_DEFAULT_MIN_VALUE 0X7F +#define HID_DEFAULT_MAX_VALUE 0x80 +#define HID_DEFAULT_SENSITIVITY 0x7F +#define HID_USAGE_SENSOR_PROPERTY_CONNECTION_TYPE_PC_INTEGRATED_ENUM 0x01 +/* state enums */ +#define HID_USAGE_SENSOR_STATE_READY_ENUM 0x02 +#define HID_USAGE_SENSOR_STATE_INITIALIZING_ENUM 0x05 +#define HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM 0x04 + +int get_report_descriptor (int sensor_idx,u8 *rep_desc) +{ +switch (sensor_idx) { +case ACCEL_IDX :/* accel */ +memset (rep_desc,0 ,sizeof (accel3_report_descriptor)); +memcpy (rep_desc, accel3_report_descriptor, +sizeof (accel3_report_descriptor)); +break ; + +case GYRO_IDX :/* gyro */ +memset (rep_desc,0 ,sizeof (gyro3_report_descriptor)); +memcpy (rep_desc, gyro3_report_descriptor, +sizeof (gyro3_report_descriptor)); +break ; + +case MAG_IDX :/* Magnetometer */ +memset (rep_desc,0 ,sizeof (comp3_report_descriptor)); +memcpy (rep_desc, comp3_report_descriptor, +sizeof (comp3_report_descriptor)); +break ; + +case AMBIENT_LIGHT_IDX :/* ambient light sensor */ +memset (rep_desc,0 ,sizeof (als_report_descriptor)); +memcpy (rep_desc, als_report_descriptor, +sizeof (als_report_descriptor)); +break ; + } +return 0 ; +} +EXPORT_SYMBOL_GPL (get_report_descriptor); + +u32 get_descriptor_size (int sensor_idx,int descriptor_name) +{ +switch (sensor_idx) { +case ACCEL_IDX : +switch (descriptor_name) { +case descr_size: +return sizeof (accel3_report_descriptor); +case input_size: +return sizeof (struct accel3_input_report ); +case feature_size: +return sizeof (struct accel3_feature_report ); + } +break ; + +case GYRO_IDX : +switch (descriptor_name) { +case descr_size: +return sizeof (gyro3_report_descriptor); +case input_size: +return sizeof (struct gyro_input_report ); +case feature_size: +return sizeof (struct gyro_feature_report ); + } +break ; + +case MAG_IDX : +switch (descriptor_name) { +case descr_size: +return sizeof (comp3_report_descriptor); +case input_size: +return sizeof (struct magno_input_report ); +case feature_size: +return sizeof (struct magno_input_report ); + } +break ; + +case AMBIENT_LIGHT_IDX : +switch (descriptor_name) { +case descr_size: +return sizeof (als_report_descriptor); +case input_size: +return sizeof (struct als_input_report ); +case feature_size: +return sizeof (struct als_feature_report ); + } +break ; + +default : +pr_info ("Unknown Sensor index detected" ); + } +return 0 ; +} +EXPORT_SYMBOL_GPL (get_descriptor_size); + +static void get_common_features (struct common_feature_property *common, +int report_id) +{ + common->report_id = report_id; + common->connection_type = +HID_USAGE_SENSOR_PROPERTY_CONNECTION_TYPE_PC_INTEGRATED_ENUM ; + common->report_state = +HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM ; + common->power_state = +HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM ; + common->sensor_state =HID_USAGE_SENSOR_STATE_INITIALIZING_ENUM ; + common->report_interval =HID_DEFAULT_REPORT_INTERVAL ; +} + +u8 get_feature_report (int sensor_idx,int report_id,u8 *feature_report) +{ +u8 report_size =0 ; +struct accel3_feature_report acc_feature; +struct gyro_feature_report gyro_feature; +struct magno_feature_report magno_feature; +struct als_feature_report als_feature; + +if (!feature_report) +return report_size; + +switch (sensor_idx) { +case ACCEL_IDX :/* accel */ +get_common_features (&acc_feature.common_property, report_id); + acc_feature.accel_change_sesnitivity = +HID_DEFAULT_SENSITIVITY ; + acc_feature.accel_sensitivity_min =HID_DEFAULT_MIN_VALUE ; + acc_feature.accel_sensitivity_max =HID_DEFAULT_MAX_VALUE ; +memcpy (feature_report, &acc_feature,sizeof (acc_feature)); + report_size =sizeof (acc_feature); +break ; + +case GYRO_IDX :/* gyro */ +get_common_features (&gyro_feature.common_property, report_id); + gyro_feature.gyro_change_sesnitivity =HID_DEFAULT_SENSITIVITY ; + gyro_feature.gyro_sensitivity_min =HID_DEFAULT_MIN_VALUE ; + gyro_feature.gyro_sensitivity_max =HID_DEFAULT_MAX_VALUE ; +memcpy (feature_report, &gyro_feature,sizeof (gyro_feature)); + report_size =sizeof (gyro_feature); +break ; + +case MAG_IDX :/* Magnetometer */ +get_common_features (&magno_feature.common_property, report_id); + magno_feature.magno_headingchange_sensitivity = +HID_DEFAULT_SENSITIVITY ; + magno_feature.heading_min =HID_DEFAULT_MIN_VALUE ; + magno_feature.heading_max =HID_DEFAULT_MAX_VALUE ; + magno_feature.flux_change_sensitivity =HID_DEFAULT_MIN_VALUE ; + magno_feature.flux_min =HID_DEFAULT_MIN_VALUE ; + magno_feature.flux_max =HID_DEFAULT_MAX_VALUE ; +memcpy (feature_report, &magno_feature,sizeof (magno_feature)); + report_size =sizeof (magno_feature); +break ; + +case AMBIENT_LIGHT_IDX :/* ambient light sensor */ +get_common_features (&als_feature.common_property, report_id); + als_feature.als_change_sesnitivity =HID_DEFAULT_SENSITIVITY ; + als_feature.als_sensitivity_min =HID_DEFAULT_MIN_VALUE ; + als_feature.als_sensitivity_max =HID_DEFAULT_MAX_VALUE ; +memcpy (feature_report, &als_feature,sizeof (als_feature)); + report_size =sizeof (als_feature); +break ; + } +return report_size; +} +EXPORT_SYMBOL_GPL (get_feature_report); + +static void get_common_inputs (struct common_input_property *common, +int report_id) +{ + common->report_id = report_id; + common->sensor_state =HID_USAGE_SENSOR_STATE_READY_ENUM ; + common->event_type =HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM ; +} + +u8 get_input_report (int sensor_idx,int report_id, +u8 *input_report,u32 *sensor_virt_addr) +{ +u8 report_size =0 ; +struct accel3_input_report acc_input; +struct gyro_input_report gyro_input; +struct magno_input_report magno_input; +struct als_input_report als_input; + +if (!sensor_virt_addr || !input_report) +return report_size; + +switch (sensor_idx) { +case ACCEL_IDX :/* accel */ +get_common_inputs (&acc_input.common_property, report_id); + acc_input.in_accel_x_value = (int )sensor_virt_addr[0 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + acc_input.in_accel_y_value = (int )sensor_virt_addr[1 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + acc_input.in_accel_z_value = (int )sensor_virt_addr[2 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; +memcpy (input_report, &acc_input,sizeof (acc_input)); + report_size =sizeof (acc_input); +break ; + +case GYRO_IDX :/* gyro */ +get_common_inputs (&gyro_input.common_property, report_id); + gyro_input.in_angel_x_value = (int )sensor_virt_addr[0 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + gyro_input.in_angel_y_value = (int )sensor_virt_addr[1 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + gyro_input.in_angel_z_value = (int )sensor_virt_addr[2 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; +memcpy (input_report, &gyro_input,sizeof (gyro_input)); + report_size =sizeof (gyro_input); +break ; + +case MAG_IDX :/* Magnetometer */ +get_common_inputs (&magno_input.common_property, report_id); + magno_input.in_magno_x = (int )sensor_virt_addr[0 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + magno_input.in_magno_y = (int )sensor_virt_addr[1 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + magno_input.in_magno_z = (int )sensor_virt_addr[2 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + magno_input.in_magno_accuracy = (u16 )sensor_virt_addr[3 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; +memcpy (input_report, &magno_input,sizeof (magno_input)); + report_size =sizeof (magno_input); +break ; + +case AMBIENT_LIGHT_IDX :/* Als */ +get_common_inputs (&als_input.common_property, report_id); + als_input.illuminance_value = (int )sensor_virt_addr[0 ] / +AMD_SFH_FIRMWARE_MULTIPLIER ; + report_size =sizeof (als_input); +memcpy (input_report, &als_input,sizeof (als_input)); +break ; + } +return report_size; +}
drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.h new file +125 -0
125 lines not on this page · raw message
drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_descriptor.h new file +642 -0
642 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 24 lines · Sandeep Singh
From: Sandeep Singh <[email protected]>
AMD SFH(Sensor Fusion Hub) is HID based driver.SFH FW is part of MP2 processor (MP2 which is an ARM® Cortex-M4 core based co-processor to x86) and it runs on MP2 where in driver resides on X86.The driver functionalities are divided into three parts:-
1: amd-mp2-pcie:- This module will communicate with MP2 FW and
provide that data into DRAM.
2: Client driver :- This part for driver will use dram data and
convert that data into HID format based on HID reports.
3: Transport driver :- This part of driver will communicate with
HID core. Communication between devices and HID core is mostly done via HID reportsIn terms of architecture it is much more reassembles like ISH(Intel Integrated Sensor Hub). However the major difference is all the hid reports are generated as part of kernel driver. AMD SFH driver taken reference from ISH in terms of design and functionalities at fewer location.
Quoted 4 lines
AMD sensor fusion Hub is part of a SOC 17h family based platforms. The solution is working well on several OEM products. AMD SFH uses HID over PCIe bus.
I can't believe this is fifth version.
Guys, you have to do much more work on these drivers.
Quoted 96 lines
Sandeep Singh (4):
SFH: Add maintainers and documentation for AMD SFH based on HID
framework
SFH: PCI driver to add support of AMD sensor fusion Hub using HID
framework
SFH: Transport Driver to add support of AMD Sensor Fusion Hub (SFH)
SFH: Create HID report to Enable support of AMD sensor fusion Hub(SFH)Changes since v1:
-Fix auto build test warnings
-Fix warnings captured using smatch
-Changes suggested by Dan CarpenterLinks of the review comments for v1:
[1] https://patchwork.kernel.org/patch/11325163/ [2] https://patchwork.kernel.org/patch/11325167/ [3] https://patchwork.kernel.org/patch/11325171/ [4] https://patchwork.kernel.org/patch/11325187/Changes since v2:
-Debugfs divided into another patch
-Fix some cosmetic changes
-Fix for review comments
Reported and Suggested by:- Srinivas PandruvadaLinks of the review comments for v2:
[1] https://patchwork.kernel.org/patch/11355491/ [2] https://patchwork.kernel.org/patch/11355495/ [3] https://patchwork.kernel.org/patch/11355499/ [4] https://patchwork.kernel.org/patch/11355503/Changes since v3:
-removed debugfs suggested by - Benjamin TissoiresLinks of the review comments for v3:
[1] https://lkml.org/lkml/2020/2/11/1256 [2] https://lkml.org/lkml/2020/2/11/1257 [3] https://lkml.org/lkml/2020/2/11/1258 [4] https://lkml.org/lkml/2020/2/11/1259 [5] https://lkml.org/lkml/2020/2/11/1260Changes since v4:
- Rework done based on review comments by - Andy Shevchenko
- changes done based on suggested by -Richard NeumannLinks of the review comments for v4:
[1] https://lkml.org/lkml/2020/2/26/1360 [2] https://lkml.org/lkml/2020/2/26/1361 [3] https://lkml.org/lkml/2020/2/26/1362 [4] https://lkml.org/lkml/2020/2/26/1363 [5] https://lkml.org/lkml/2020/2/27/1Sandeep Singh (4):
SFH: Add maintainers and documentation for AMD SFH based on HID
framework
SFH: PCI driver to add support of AMD sensor fusion Hub using HID
framework
SFH: Transport Driver to add support of AMD Sensor Fusion Hub (SFH
SFH: Create HID report to Enable support of AMD sensor fusion Hub(SFH)Documentation/hid/amd-sfh-hid.rst | 160 +++++ MAINTAINERS | 8 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 1 + drivers/hid/amd-sfh-hid/Kconfig | 21 + drivers/hid/amd-sfh-hid/Makefile | 16 + drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 196 +++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 137 +++++ drivers/hid/amd-sfh-hid/amdsfh-hid-client.c | 256 ++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 ++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 84 +++ .../hid_descriptor/amd_sfh_hid_descriptor.c | 251 ++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 14 files changed, 2078 insertions(+) create mode 100644 Documentation/hid/amd-sfh-hid.rst create mode 100644 drivers/hid/amd-sfh-hid/Kconfig create mode 100644 drivers/hid/amd-sfh-hid/Makefile create mode 100644 drivers/hid/amd-sfh-hid/amd_mp2_pcie.c create mode 100644 drivers/hid/amd-sfh-hid/amd_mp2_pcie.h create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid-client.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-hid.h create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.c create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.h create mode 100644 drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_descriptor.h--
2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 25 lines · Andy Shevchenko
Quoted 24 lines · Sandeep Singh
From: Sandeep Singh <[email protected]>
AMD SFH(Sensor Fusion Hub) is HID based driver.SFH FW is part of MP2 processor (MP2 which is an ARM® Cortex-M4 core based co-processor to x86) and it runs on MP2 where in driver resides on X86.The driver functionalities are divided into three parts:-
1: amd-mp2-pcie:- This module will communicate with MP2 FW and
provide that data into DRAM.
2: Client driver :- This part for driver will use dram data and
convert that data into HID format based on HID reports.
3: Transport driver :- This part of driver will communicate with
HID core. Communication between devices and HID core is mostly done via HID reportsIn terms of architecture it is much more reassembles like ISH(Intel Integrated Sensor Hub). However the major difference is all the hid reports are generated as part of kernel driver. AMD SFH driver taken reference from ISH in terms of design and functionalities at fewer location.
Quoted 7 lines
Quoted 4 lines
AMD sensor fusion Hub is part of a SOC 17h family based platforms. The solution is working well on several OEM products. AMD SFH uses HID over PCIe bus.
I can't believe this is fifth version.
Guys, you have to do much more work on these drivers.
Is there any active development addressing Andy's comments? Else can we support you to bring these patches mainline?
Regards,
Marco
Hi,
Am Dienstag, den 28.07.2020, 16:58 +0200 schrieb Marco Felsch:
Quoted 41 lines
Hi,
Quoted 29 lines · Andy Shevchenko
Quoted 27 lines · Sandeep Singh
From: Sandeep Singh <[email protected]>
AMD SFH(Sensor Fusion Hub) is HID based driver.SFH FW is part of MP2 processor (MP2 which is an ARM® Cortex-M4 core based co-processor to x86) and it runs on MP2 where in driver resides on X86.The driver functionalities are divided into three parts:-
1: amd-mp2-pcie:- This module will communicate with MP2 FW
and
provide that data into DRAM.
2: Client driver :- This part for driver will use dram data
and
convert that data into HID format based
on
HID reports.
3: Transport driver :- This part of driver will communicate with
HID core. Communication between devices
and
HID core is mostly done via HID reportsIn terms of architecture it is much more reassembles like ISH(Intel Integrated Sensor Hub). However the major difference is all the hid reports are generated as part of kernel driver. AMD SFH driver taken reference from ISH in terms of design and functionalities at fewer location.
Quoted 8 lines
Quoted 5 lines
AMD sensor fusion Hub is part of a SOC 17h family based platforms.
The solution is working well on several OEM products. AMD SFH uses HID over PCIe bus.I can't believe this is fifth version.
Guys, you have to do much more work on these drivers.
Quoted 6 lines
Is there any active development addressing Andy's comments? Else can we
support you to bring these patches mainline?Regards,
Marco
I did some major refactoring¹ on the v4 patch series and am currently providing it for Arch Linux as a DKMS package in the AUR².
A teensy bit of my changes seems to have influenced the v5 version but I actually did some major changes, like strictly separating the HID, platform and PCI driver parts.
I did not submit my changes for upstream so far, since I do not want to undermine AMD's work on this nor cause competing driver implementations.
Sincerely,
Richard
[1] https://github.com/conqp/linux/tree/amd-sfh-hid/drivers/hid/amd-sfh-hid
[2] https://aur.archlinux.org/packages/amd-sfh-hid-dkms/
Hi Richard,
Quoted 10 lines · Richard Neumann
Hi,
Am Dienstag, den 28.07.2020, 16:58 +0200 schrieb Marco Felsch:
Quoted 7 lines
Hi,
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Sandeep Singh
From: Sandeep Singh <[email protected]>
...
Quoted 19 lines
Quoted 9 lines
Quoted 2 lines
I can't believe this is fifth version.
Guys, you have to do much more work on these drivers.Is there any active development addressing Andy's comments? Else can we
support you to bring these patches mainline?Regards,
MarcoI did some major refactoring¹ on the v4 patch series and am currently providing it for Arch Linux as a DKMS package in the AUR².
A teensy bit of my changes seems to have influenced the v5 version but I actually did some major changes, like strictly separating the HID, platform and PCI driver parts.
I did not submit my changes for upstream so far, since I do not want to undermine AMD's work on this nor cause competing driver implementations.
Quoted 6 lines
Sincerely,
Richard
[1] https://github.com/conqp/linux/tree/amd-sfh-hid/drivers/hid/amd-sfh-hid
[2] https://aur.archlinux.org/packages/amd-sfh-hid-dkms/
Thanks for the links :) We should get this work done to improve user experience. Let's wait for the AMD developers comments and then we can discuss the further steps :)
Regards,
Marco