SFH: Add Support for AMD Sensor Fusion Hub
Subsystems (4)
v3 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 (5):
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: Add debugfs support to AMD Sensor Fusion Hub
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/
Documentation/hid/amd-sfh-hid.rst | 160 +++++ MAINTAINERS | 8 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 1 + drivers/hid/amd-sfh-hid/Kconfig | 20 + drivers/hid/amd-sfh-hid/Makefile | 17 + drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 243 ++++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 177 ++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.c | 250 ++++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.h | 14 + drivers/hid/amd-sfh-hid/amdsfh-hid-client.c | 260 +++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 ++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 85 +++ .../hid_descriptor/amd_sfh_hid_descriptor.c | 275 +++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 16 files changed, 2458 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-debugfs.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-debugfs.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 v3 1/5 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 v3 2/5 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 | 20 +++ drivers/hid/amd-sfh-hid/Makefile | 17 +++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 243 +++++++++++++++++++++++++++++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 177 ++++++++++++++++++++++++ 6 files changed, 460 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 +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +menu "AMD SFH HID support" + depends on (X86_64 || COMPILE_TEST) && 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 +17 -0
@@ -0,0 +1,17 @@ +# 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+= amdsfh-debugfs.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 +243 -0
243 lines not on this page · raw message
drivers/hid/amd-sfh-hid/amd_mp2_pcie.h new file +177 -0
177 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 3/5 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 | 260 ++++++++++++++++++++++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 +++++++++++++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 85 +++++++++ 3 files changed, 524 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 +260 -0
@@ -0,0 +1,260 @@ +// 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 "amdsfh-debugfs.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); + +amdsfh_debugfs_setup (cl_data); + +for (i =0 ; i < cl_data->num_hid_devices; i++) { + cl_data->sensor_virt_addr[i] =dma_alloc_coherent + (&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); +amdsfh_debugfs_destroy (cl_data); +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 (&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 +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 4/5 SFH: Add debugfs support to AMD Sensor Fusion Hub
In reply to Sandeep SinghFrom: Sandeep Singh <[email protected]>
This part would give access to internals of
AMD Sensor Fusion Hub through debugfs. it provide raw values in debugfs
--- drivers/hid/amd-sfh-hid/amdsfh-debugfs.c | 250 +++++++++++++++++++++++++++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.h | 14 ++ 2 files changed, 264 insertions(+) create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-debugfs.c create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-debugfs.h
drivers/hid/amd-sfh-hid/amdsfh-debugfs.c new file +250 -0
@@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* AMD SFH Debugfs +* This part would access MP2 registers through debugfs +* for AMD SFH debugging. +* Author: Nehal Bakulchandra Shah <[email protected]> +*/ + +#include <linux/slab.h> +#include "amd_mp2_pcie.h" +#include "amdsfh-debugfs.h" + +/* DebugFS helpers */ +#define OBUFP (obuf + oboff) +#define OBUFLEN 512 +#define OBUFSPC (OBUFLEN - oboff) +#define OSCNPRINTF (fmt, ...) \ + scnprintf(OBUFP, OBUFSPC, fmt, ## __VA_ARGS__) + +static ssize_t amdsfh_debugfs_accel_read (struct file *filp,char __user *ubuf, +size_t count,loff_t *offp) +{ +unsigned int oboff =0 , i; +struct amdtp_cl_data *cl_data = filp->private_data; +bool found = false; +ssize_t ret; +char *obuf; + +for (i =0 ; i < cl_data->num_hid_devices; i++) { +if (cl_data->sensor_idx[i] ==ACCEL_IDX ) { + found = true; +break ; + } + } + +if (!found) +return -1 ; + + obuf =kmalloc (OBUFLEN ,GFP_KERNEL ); +if (!obuf) +return -ENOMEM ; + + oboff +=OSCNPRINTF ("Accel_X_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][0 ]); + oboff +=OSCNPRINTF ("Accel_Y_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][1 ]); + oboff +=OSCNPRINTF ("Accel_Z_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][2 ]); + ret =simple_read_from_buffer (ubuf, count, offp, obuf, oboff); + +kfree (obuf); + +return ret; +} + +static ssize_t amdsfh_debugfs_gyro_read (struct file *filp,char __user *ubuf, +size_t count,loff_t *offp) +{ +unsigned int oboff =0 , i; +bool found = false; +struct amdtp_cl_data *cl_data = filp->private_data; +ssize_t ret; +char *obuf; + +for (i =0 ; i < cl_data->num_hid_devices; i++) { +if (cl_data->sensor_idx[i] ==GYRO_IDX ) { + found = true; +break ; + } + } + +if (!found) +return -1 ; + + obuf =kmalloc (OBUFLEN ,GFP_KERNEL ); +if (!obuf) +return -ENOMEM ; + + oboff +=OSCNPRINTF ("Gyro_X_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][0 ]); + oboff +=OSCNPRINTF ("Gyro_Y_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][1 ]); + oboff +=OSCNPRINTF ("Gyro_Z_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][2 ]); + ret =simple_read_from_buffer (ubuf, count, offp, obuf, oboff); + +kfree (obuf); + +return ret; +} + +static ssize_t amdsfh_debugfs_mag_read (struct file *filp,char __user *ubuf, +size_t count,loff_t *offp) +{ +unsigned int oboff =0 , i; +bool found = false; +ssize_t ret; +char *obuf; +struct amdtp_cl_data *cl_data = filp->private_data; + +for (i =0 ; i < cl_data->num_hid_devices; i++) { +if (cl_data->sensor_idx[i] ==MAG_IDX ) { + found = true; +break ; + } + } + +if (!found) +return -1 ; + + obuf =kmalloc (OBUFLEN ,GFP_KERNEL ); +if (!obuf) +return -ENOMEM ; + + oboff +=OSCNPRINTF ("Mag_X_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][0 ]); + oboff +=OSCNPRINTF ("Mag_Y_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][1 ]); + oboff +=OSCNPRINTF ("Mag_Z_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][2 ]); + ret =simple_read_from_buffer (ubuf, count, offp, obuf, oboff); + +kfree (obuf); + +return ret; +} + +static ssize_t amdsfh_debugfs_als_read (struct file *filp,char __user *ubuf, +size_t count,loff_t *offp) +{ +unsigned int oboff =0 , i; +bool found = false; +ssize_t ret; +char *obuf; +struct amdtp_cl_data *cl_data = filp->private_data; + +for (i =0 ; i < cl_data->num_hid_devices; i++) { +if (cl_data->sensor_idx[i] ==AMBIENT_LIGHT_IDX ) { + found = true; +break ; + } + } + +if (!found) +return -1 ; + + obuf =kmalloc (OBUFLEN ,GFP_KERNEL ); +if (!obuf) +return -ENOMEM ; + + oboff +=OSCNPRINTF ("Gyro_X_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][0 ]); + oboff +=OSCNPRINTF ("Gyro_Y_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][1 ]); + oboff +=OSCNPRINTF ("Gyro_Z_Raw:%d\n" , + (int )cl_data->sensor_virt_addr[i][2 ]); + ret =simple_read_from_buffer (ubuf, count, offp, obuf, oboff); + +kfree (obuf); + +return ret; +} + +static const struct file_operations amdsfh_debugfs_accel_ops = { + .owner =THIS_MODULE , + .open = simple_open, + .read = amdsfh_debugfs_accel_read, +}; + +static const struct file_operations amdsfh_debugfs_gyro_ops = { + .owner =THIS_MODULE , + .open = simple_open, + .read = amdsfh_debugfs_gyro_read, +}; + +static const struct file_operations amdsfh_debugfs_mag_ops = { + .owner =THIS_MODULE , + .open = simple_open, + .read = amdsfh_debugfs_mag_read, +}; + +static const struct file_operations amdsfh_debugfs_als_ops = { + .owner =THIS_MODULE , + .open = simple_open, + .read = amdsfh_debugfs_als_read, +}; + +int amdsfh_debugfs_setup (struct amdtp_cl_data *cl_data) +{ +/* DebugFS info */ +struct dentry *dbgfs; +int i; + +if (!debugfs_initialized ()) +return -1 ; + +if (!cl_data->amd_debugfs_dir) + cl_data->amd_debugfs_dir =debugfs_create_dir + (KBUILD_MODNAME ,NULL ); + +if (!cl_data->amd_debugfs_dir) +return -1 ; + +for (i =0 ; i < cl_data->num_hid_devices; i++) { +switch (cl_data->sensor_idx[i]) { +case ACCEL_IDX : + dbgfs =debugfs_create_dir ("accel" , + cl_data->amd_debugfs_dir); +debugfs_create_file ("raw_value" ,0400 , + dbgfs, cl_data, + &amdsfh_debugfs_accel_ops); +break ; + +case GYRO_IDX : + dbgfs =debugfs_create_dir ("gyro" , + cl_data->amd_debugfs_dir); +debugfs_create_file ("raw_value" ,0400 , + dbgfs, cl_data, + &amdsfh_debugfs_gyro_ops); +break ; + +case MAG_IDX : + dbgfs =debugfs_create_dir ("magnetometer" , + cl_data->amd_debugfs_dir); +debugfs_create_file ("raw_value" ,0400 , + dbgfs, cl_data, + &amdsfh_debugfs_mag_ops); +break ; + +case AMBIENT_LIGHT_IDX : + dbgfs =debugfs_create_dir ("als" , + cl_data->amd_debugfs_dir); +debugfs_create_file ("raw_value" ,0400 , + dbgfs, cl_data, + &amdsfh_debugfs_als_ops); +break ; + +default : +return 0 ; + } + } +return 0 ; +} +EXPORT_SYMBOL (amdsfh_debugfs_setup); + +void amdsfh_debugfs_destroy (struct amdtp_cl_data *cl_data) +{ +debugfs_remove_recursive (cl_data->amd_debugfs_dir); +} +EXPORT_SYMBOL (amdsfh_debugfs_destroy);
drivers/hid/amd-sfh-hid/amdsfh-debugfs.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* AMD SFH DebugFS +* Author: Nehal Bakulchandra Shah <[email protected]> +*/ +#include "amdsfh-hid.h" + +#ifndef AMDSFH_DEBUGFS_H +#define AMDSFH_DEBUGFS_H + +int amdsfh_debugfs_setup (struct amdtp_cl_data *cl_data); +void amdsfh_debugfs_destroy (struct amdtp_cl_data *cl_data); + +#endif
Signature · 1 line
2.7.4
PATCH v3 5/5 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 | 275 +++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 3 files changed, 1042 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 +275 -0
@@ -0,0 +1,275 @@ +// 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 : +if (descriptor_name == descr_size) +return sizeof (accel3_report_descriptor); +else if (descriptor_name == input_size) +return sizeof (struct accel3_input_report ); +else if (descriptor_name == feature_size) +return sizeof (struct accel3_feature_report ); +break ; + +case GYRO_IDX : +if (descriptor_name == descr_size) +return sizeof (gyro3_report_descriptor); +else if (descriptor_name == input_size) +return sizeof (struct gyro_input_report ); +else if (descriptor_name == feature_size) +return sizeof (struct gyro_feature_report ); +break ; + +case MAG_IDX : +if (descriptor_name == descr_size) +return sizeof (comp3_report_descriptor); +else if (descriptor_name == input_size) +return sizeof (struct magno_input_report ); +else if (descriptor_name == feature_size) +return sizeof (struct magno_input_report ); +break ; + +case AMBIENT_LIGHT_IDX : +if (descriptor_name == descr_size) +return sizeof (als_report_descriptor); +else if (descriptor_name == input_size) +return sizeof (struct als_input_report ); +else if (descriptor_name == feature_size) +return sizeof (struct als_feature_report ); +break ; + +default : +pr_info ("Unknown Sensor index detected" ); + } +return 0 ; +} +EXPORT_SYMBOL_GPL (get_descriptor_size); + +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 */ + acc_feature.common_property.connection_type = +HID_USAGE_SENSOR_PROPERTY_CONNECTION_TYPE_PC_INTEGRATED_ENUM ; + acc_feature.common_property.report_state = +HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM ; + acc_feature.common_property.power_state = +HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM ; + acc_feature.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_INITIALIZING_ENUM ; + acc_feature.common_property.report_interval = +HID_DEFAULT_REPORT_INTERVAL ; + 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 */ + gyro_feature.common_property.connection_type = +HID_USAGE_SENSOR_PROPERTY_CONNECTION_TYPE_PC_INTEGRATED_ENUM ; + gyro_feature.common_property.report_state = +HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM ; + gyro_feature.common_property.power_state = +HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM ; + gyro_feature.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_INITIALIZING_ENUM ; + gyro_feature.common_property.report_interval = +HID_DEFAULT_REPORT_INTERVAL ; + 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 */ + magno_feature.common_property.report_id = report_id; + magno_feature.common_property.connection_type = +HID_USAGE_SENSOR_PROPERTY_CONNECTION_TYPE_PC_INTEGRATED_ENUM ; + magno_feature.common_property.report_state = +HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM ; + magno_feature.common_property.power_state = +HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM ; + magno_feature.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_INITIALIZING_ENUM ; + magno_feature.common_property.report_interval = +HID_DEFAULT_REPORT_INTERVAL ; + 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 */ + als_feature.common_property.report_id = report_id; + als_feature.common_property.connection_type = +HID_USAGE_SENSOR_PROPERTY_CONNECTION_TYPE_PC_INTEGRATED_ENUM ; + als_feature.common_property.report_state = +HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM ; + als_feature.common_property.power_state = +HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM ; + als_feature.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_INITIALIZING_ENUM ; + als_feature.common_property.report_interval = +HID_DEFAULT_REPORT_INTERVAL ; + 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); + +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 */ + acc_input.common_property.report_id = report_id; + acc_input.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_READY_ENUM ; + acc_input.common_property.event_type = +HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM ; + 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 */ + gyro_input.common_property.report_id = report_id; + gyro_input.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_READY_ENUM ; + gyro_input.common_property.event_type = +HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM ; + 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 */ + magno_input.common_property.report_id = report_id; + magno_input.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_READY_ENUM ; + magno_input.common_property.event_type = +HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM ; + 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 */ + als_input.common_property.report_id = report_id; + als_input.common_property.sensor_state = +HID_USAGE_SENSOR_STATE_READY_ENUM ; + als_input.common_property.event_type = +HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM ; + 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
Hi,
Quoted 23 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 3 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 started looking at this patch because of the phoronix' news item on it.
First of all I want to say that it is great that AMD is working on getting the Sensor Fusion Hub supported on Linux and that you are working on a driver for this.
But, I've taken a quick look, mainly at the
"[PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)" patch.
AFAIK with the Intel ISH the sensor-hub itself is actually providing HID descriptors and HID input reports.
Looking at the AMD code, that does not seem to be the case, it seems the values come directly from the AMD sensor-hub without being in any HID specific form, e.g.:
+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 */
+ acc_input.common_property.report_id = report_id;
+ acc_input.common_property.sensor_state =
+ HID_USAGE_SENSOR_STATE_READY_ENUM;
+ acc_input.common_property.event_type =
+ HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM;
+ 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;
And the descriptors are hardcoded in the driver so as to fake a HID device.
So going through the HID subsystem seems like an unnecessary detour, which just makes things needlessly complex and harder to debug (and extend).
The HID devices which the current patch-set is creating ultimately will result in a number of devices being created under
/sys/bus/iio/devices
And this are the devices which userspace uses to get the sensor data.
IMHO instead of going through the HID subsys the AMD Sensor Fusion Hub driver should simply register 4 (*) iio-devices itself and directly pass the data through at the iio subsys level rather then going the long way around by creating a fake HID device which then gets attached to by the hid-sensor driver to ultimately create the same iio-devices.
There are examples of e.g. various iio accel drivers under:drivers/iio/accel/ you could start with a simple driver supporting just the accelerometer bits and then extend things from there.
Benjamin, Jiri, Jonathan, what is your take on this?
Regards,
Hans
*) One for accel, gyra, magneto and light each
Quoted 66 lines
Sandeep Singh (5):
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: Add debugfs support to AMD Sensor Fusion Hub
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/Documentation/hid/amd-sfh-hid.rst | 160 +++++ MAINTAINERS | 8 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 1 + drivers/hid/amd-sfh-hid/Kconfig | 20 + drivers/hid/amd-sfh-hid/Makefile | 17 + drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 243 ++++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 177 ++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.c | 250 ++++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.h | 14 + drivers/hid/amd-sfh-hid/amdsfh-hid-client.c | 260 +++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 ++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 85 +++ .../hid_descriptor/amd_sfh_hid_descriptor.c | 275 +++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 16 files changed, 2458 insertions(+)create mode 100644
Documentation/hid/amd-sfh-hid.rst
create mode 100644drivers/hid/amd-sfh-hid/Kconfig
create mode 100644drivers/hid/amd-sfh-hid/Makefile
create mode 100644drivers/hid/amd-sfh-hid/amd_mp2_pcie.c
create mode 100644drivers/hid/amd-sfh-hid/amd_mp2_pcie.h
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-debugfs.c
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-debugfs.h
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid-client.c
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid.c
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid.h
create mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.ccreate mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.hcreate mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_descriptor.h
Hi,
Quoted 31 lines · Hans de Goede
Hi,
Quoted 23 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 3 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.
Quoted 5 lines
I started looking at this patch because of the phoronix' news item on it.
First of all I want to say that it is great that AMD is working on getting the Sensor Fusion Hub supported on Linux and that you are working on a driver for this.
Yep, couldn't agree more :)
Quoted 62 lines
But, I've taken a quick look, mainly at the
"[PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)" patch.AFAIK with the Intel ISH the sensor-hub itself is actually providing HID descriptors and HID input reports.
Looking at the AMD code, that does not seem to be the case, it seems the values come directly from the AMD sensor-hub without being in any HID specific form, e.g.:
(quoted diff) +28
-0+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 */ + acc_input.common_property.report_id = report_id; + acc_input.common_property.sensor_state = + HID_USAGE_SENSOR_STATE_READY_ENUM; + acc_input.common_property.event_type = + HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM; + 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;And the descriptors are hardcoded in the driver so as to fake a HID device.
So going through the HID subsystem seems like an unnecessary detour, which just makes things needlessly complex and harder to debug (and extend).
The HID devices which the current patch-set is creating ultimately will result in a number of devices being created under
/sys/bus/iio/devicesAnd this are the devices which userspace uses to get the sensor data.
IMHO instead of going through the HID subsys the AMD Sensor Fusion Hub driver should simply register 4 (*) iio-devices itself and directly pass the data through at the iio subsys level rather then going the long way around by creating a fake HID device which then gets attached to by the hid-sensor driver to ultimately create the same iio-devices.
Quoted 5 lines
There are examples of e.g. various iio accel drivers under:
drivers/iio/accel/you could start with a simple driver supporting just the accelerometer bits and then extend things from there.Benjamin, Jiri, Jonathan, what is your take on this?
Hard to say without knowing AMD roadmap for that. If they intend to have an ISH-like approach in the end with reports and descriptors provided by the firmwares, then it makes sense to keep this architecture for the first revision of devices.
If not, then yes, this is probably overkill compared to what needs to be done.
Sandeep, can you explain to us why you think using HID is the best way?
On a side note, I don't necessarily like patch 4/5 with the debugfs interface. It's adding a kernel API for no gain, and we should already have the debug API available in the various subsystems involved.
Cheers,
Benjamin
Quoted 76 lines
Regards,
Hans
*) One for accel, gyra, magneto and light each
Quoted 66 lines
Sandeep Singh (5):
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: Add debugfs support to AMD Sensor Fusion Hub
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/Documentation/hid/amd-sfh-hid.rst | 160 +++++ MAINTAINERS | 8 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 1 + drivers/hid/amd-sfh-hid/Kconfig | 20 + drivers/hid/amd-sfh-hid/Makefile | 17 + drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 243 ++++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 177 ++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.c | 250 ++++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.h | 14 + drivers/hid/amd-sfh-hid/amdsfh-hid-client.c | 260 +++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 ++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 85 +++ .../hid_descriptor/amd_sfh_hid_descriptor.c | 275 +++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 16 files changed, 2458 insertions(+)create mode 100644
Documentation/hid/amd-sfh-hid.rst
create mode 100644drivers/hid/amd-sfh-hid/Kconfig
create mode 100644drivers/hid/amd-sfh-hid/Makefile
create mode 100644drivers/hid/amd-sfh-hid/amd_mp2_pcie.c
create mode 100644drivers/hid/amd-sfh-hid/amd_mp2_pcie.h
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-debugfs.c
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-debugfs.h
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid-client.c
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid.c
create mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid.h
create mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.ccreate mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.hcreate mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_descriptor.h
Quoted 129 lines · Benjamin Tissoires
Hi,
Quoted 35 lines · Hans de Goede
Hi,
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 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.Quoted 6 lines
I started looking at this patch because of the phoronix' news item on it.
First of all I want to say that it is great that AMD is working on getting the Sensor Fusion Hub supported on Linux and that you are working on a driver for this.
Yep, couldn't agree more :)
Quoted 81 lines
But, I've taken a quick look, mainly at the
"[PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)"
patch.AFAIK with the Intel ISH the sensor-hub itself is actually providing
HID descriptors and HID input reports.Looking at the AMD code, that does not seem to be the case, it seems
the values come directly from the AMD sensor-hub without being in any
HID specific form, e.g.:(quoted diff) +17
-0+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 */ + acc_input.common_property.report_id = report_id; + acc_input.common_property.sensor_state = + HID_USAGE_SENSOR_STATE_READ
Y_ENUM;(quoted diff) +2
-0+ acc_input.common_property.event_type = + HID_USAGE_SENSOR_EVENT_DATA_UPDATED
_ENUM;
+ acc_input.in_accel_x_value =
(int)sensor_virt_addr[0] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_y_value =
(int)sensor_virt_addr[1] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_z_value
= (int)sensor_virt_addr[2] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ memcpy(input_report,&acc_input,sizeof(acc_input));(quoted diff) +2
-0+ report_size = sizeof(acc_input); + break;And the descriptors are hardcoded in the driver so as to fake a HID device.
So going through the HID subsystem seems like an unnecessary detour,
which just makes things needlessly complex and harder to debug (and extend).The HID devices which the current patch-set is creating ultimately will result in a number of devices being created under
/sys/bus/iio/devicesAnd this are the devices which userspace uses to get the sensor data.
IMHO instead of going through the HID subsys the AMD Sensor Fusion Hub
driver should simply register 4 (*) iio-devices itself and directly pass the data through at the iio subsys level rather then going the long way around by creating a fake HID device which then gets attached to by the hid-sensor driver to ultimately create the same iio-devices.There are examples of e.g. various iio accel drivers under:
drivers/iio/accel/you could start with a simple driver supporting just the accelerometer bits and then extend things from there.
Quoted 9 lines
Quoted 1 line
Benjamin, Jiri, Jonathan, what is your take on this?
Hard to say without knowing AMD roadmap for that. If they intend to have an ISH-like approach in the end with reports and descriptors provided by the firmwares, then it makes sense to keep this architecture for the first revision of devices.
If not, then yes, this is probably overkill compared to what needs to be done.
I suggested this approach to follow something like Chrome-OS EC based hub, but looks like in longer run this may come from firmware. That's why they may have decided.
Thanks,
Srinivas
Quoted 100 lines
Sandeep, can you explain to us why you think using HID is the best way?
On a side note, I don't necessarily like patch 4/5 with the debugfs interface. It's adding a kernel API for no gain, and we should already
have the debug API available in the various subsystems involved.Cheers,
BenjaminQuoted 86 lines
Regards,
Hans
*) One for accel, gyra, magneto and light each
Quoted 78 lines
Sandeep Singh (5):
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: Add debugfs support to AMD Sensor Fusion Hub
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/Documentation/hid/amd-sfh-hid.rst | 160 +++++ MAINTAINERS | 8 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 1 + drivers/hid/amd-sfh-hid/Kconfig | 20 + drivers/hid/amd-sfh-hid/Makefile | 17 + drivers/hid/amd-sfh-hid/amd_mp2_pcie.c | 243 ++++++++ drivers/hid/amd-sfh-hid/amd_mp2_pcie.h | 177 ++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.c | 250 ++++++++ drivers/hid/amd-sfh-hid/amdsfh-debugfs.h | 14 + drivers/hid/amd-sfh-hid/amdsfh-hid-client.c | 260 +++++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.c | 179 ++++++ drivers/hid/amd-sfh-hid/amdsfh-hid.h | 85 +++ .../hid_descriptor/amd_sfh_hid_descriptor.c | 275 +++++++++ .../hid_descriptor/amd_sfh_hid_descriptor.h | 125 ++++ .../hid_descriptor/amd_sfh_hid_report_descriptor.h | 642 +++++++++++++++++++++ 16 files changed, 2458 insertions(+)create mode 100644
Documentation/hid/amd-sfh-hid.rstcreate mode 100644drivers/hid/amd-sfh-hid/Kconfigcreate mode 100644drivers/hid/amd-sfh-hid/Makefilecreate mode 100644drivers/hid/amd-sfh-hid/amd_mp2_pcie.ccreate mode 100644drivers/hid/amd-sfh-hid/amd_mp2_pcie.hcreate mode 100644drivers/hid/amd-sfh-hid/amdsfh-debugfs.ccreate mode 100644drivers/hid/amd-sfh-hid/amdsfh-debugfs.hcreate mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid-client.ccreate mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid.ccreate mode 100644drivers/hid/amd-sfh-hid/amdsfh-hid.hcreate mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.c
create mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_descriptor.h
create mode 100644drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_descriptor.h
Hi
Quoted 39 lines · Srinivas Pandruvada
Quoted 38 lines · Benjamin Tissoires
Hi,
Quoted 34 lines · Hans de Goede
Hi,
Quoted 31 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.
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.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
I started looking at this patch because of the phoronix' news item on it.
First of all I want to say that it is great that AMD is working on getting the Sensor Fusion Hub supported on Linux and that you are working on a driver for this.
Thanks for the valuable input.
Quoted 93 lines
Quoted 81 lines
But, I've taken a quick look, mainly at the
"[PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)"
patch.AFAIK with the Intel ISH the sensor-hub itself is actually providing
HID descriptors and HID input reports.Looking at the AMD code, that does not seem to be the case, it seems
the values come directly from the AMD sensor-hub without being in any
HID specific form, e.g.:(quoted diff) +17
-0+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 */ + acc_input.common_property.report_id = report_id; + acc_input.common_property.sensor_state = + HID_USAGE_SENSOR_STATE_READ
Y_ENUM;(quoted diff) +2
-0+ acc_input.common_property.event_type = + HID_USAGE_SENSOR_EVENT_DATA_UPDATED
_ENUM;
+ acc_input.in_accel_x_value =
(int)sensor_virt_addr[0] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_y_value =
(int)sensor_virt_addr[1] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_z_value
= (int)sensor_virt_addr[2] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ memcpy(input_report,&acc_input,sizeof(acc_input));(quoted diff) +2
-0+ report_size = sizeof(acc_input); + break;And the descriptors are hardcoded in the driver so as to fake a HID device.
So going through the HID subsystem seems like an unnecessary detour,
which just makes things needlessly complex and harder to debug (and extend).The HID devices which the current patch-set is creating ultimately will result in a number of devices being created under
/sys/bus/iio/devicesAnd this are the devices which userspace uses to get the sensor data.
IMHO instead of going through the HID subsys the AMD Sensor Fusion Hub
driver should simply register 4 (*) iio-devices itself and directly pass the data through at the iio subsys level rather then going the long way around by creating a fake HID device which then gets attached to by the hid-sensor driver to ultimately create the same iio-devices.There are examples of e.g. various iio accel drivers under:
drivers/iio/accel/you could start with a simple driver supporting just the accelerometer bits and then extend things from there.Quoted 8 lines
Benjamin, Jiri, Jonathan, what is your take on this?
Hard to say without knowing AMD roadmap for that. If they intend to have an ISH-like approach in the end with reports and descriptors provided by the firmwares, then it makes sense to keep this architecture for the first revision of devices.
If not, then yes, this is probably overkill compared to what needs to be done.I suggested this approach to follow something like Chrome-OS EC based hub, but looks like in longer run this may come from firmware. That's why they may have decided.
Quoted 14 lines
Thanks,
SrinivasQuoted 10 lines
Sandeep, can you explain to us why you think using HID is the best way?
On a side note, I don't necessarily like patch 4/5 with the debugfs interface. It's adding a kernel API for no gain, and we should already
have the debug API available in the various subsystems involved.Cheers,
Benjamin
Yes today, the HID Reports are getting generated in driver. But, we would like to have HID based driver as we may go for HID based firmware in future . Hence keeping that in mind current AMD SFH design.
So, kindly consider our design w.r.t HID for this patch series.
For the debugfs part,currently it is really handy for us to debug raw values coming from firmware.But if guys feel that it is not necessary, we can remove it.
Thanks
Nehal Shah
Hi,
Quoted 154 lines · Nehal-bakulchandra
Hi
Quoted 39 lines · Srinivas Pandruvada
Quoted 38 lines · Benjamin Tissoires
Hi,
Quoted 34 lines · Hans de Goede
Hi,
Quoted 31 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.
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.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
I started looking at this patch because of the phoronix' news item on it.
First of all I want to say that it is great that AMD is working on getting the Sensor Fusion Hub supported on Linux and that you are working on a driver for this.
Thanks for the valuable input.
Quoted 105 lines
Quoted 81 lines
But, I've taken a quick look, mainly at the
"[PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)"
patch.AFAIK with the Intel ISH the sensor-hub itself is actually providing
HID descriptors and HID input reports.Looking at the AMD code, that does not seem to be the case, it seems
the values come directly from the AMD sensor-hub without being in any
HID specific form, e.g.:(quoted diff) +17
-0+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 */ + acc_input.common_property.report_id = report_id; + acc_input.common_property.sensor_state = + HID_USAGE_SENSOR_STATE_READ
Y_ENUM;(quoted diff) +2
-0+ acc_input.common_property.event_type = + HID_USAGE_SENSOR_EVENT_DATA_UPDATED
_ENUM;
+ acc_input.in_accel_x_value =
(int)sensor_virt_addr[0] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_y_value =
(int)sensor_virt_addr[1] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_z_value
= (int)sensor_virt_addr[2] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ memcpy(input_report,&acc_input,sizeof(acc_input));(quoted diff) +2
-0+ report_size = sizeof(acc_input); + break;And the descriptors are hardcoded in the driver so as to fake a HID device.
So going through the HID subsystem seems like an unnecessary detour,
which just makes things needlessly complex and harder to debug (and extend).The HID devices which the current patch-set is creating ultimately will result in a number of devices being created under
/sys/bus/iio/devicesAnd this are the devices which userspace uses to get the sensor data.
IMHO instead of going through the HID subsys the AMD Sensor Fusion Hub
driver should simply register 4 (*) iio-devices itself and directly pass the data through at the iio subsys level rather then going the long way around by creating a fake HID device which then gets attached to by the hid-sensor driver to ultimately create the same iio-devices.There are examples of e.g. various iio accel drivers under:
drivers/iio/accel/you could start with a simple driver supporting just the accelerometer bits and then extend things from there.Quoted 8 lines
Benjamin, Jiri, Jonathan, what is your take on this?
Hard to say without knowing AMD roadmap for that. If they intend to have an ISH-like approach in the end with reports and descriptors provided by the firmwares, then it makes sense to keep this architecture for the first revision of devices.
If not, then yes, this is probably overkill compared to what needs to be done.I suggested this approach to follow something like Chrome-OS EC based hub, but looks like in longer run this may come from firmware. That's why they may have decided.
Thanks,
SrinivasQuoted 8 lines
Sandeep, can you explain to us why you think using HID is the best way?
On a side note, I don't necessarily like patch 4/5 with the debugfs interface. It's adding a kernel API for no gain, and we should already
have the debug API available in the various subsystems involved.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Cheers,
BenjaminYes today, the HID Reports are getting generated in driver. But, we would like to have HID based driver as we may go for HID based firmware in future . Hence keeping that in mind current AMD SFH design.
So, kindly consider our design w.r.t HID for this patch series.
If the plan is to move to using HID in the future and the HID maintainers (Benjamin and Jiri) are ok with the current approach then I'm fine with the current approach too.
Regards,
Hans
Quoted 155 lines · Nehal-bakulchandra
Hi
Quoted 39 lines · Srinivas Pandruvada
Quoted 38 lines · Benjamin Tissoires
Hi,
Quoted 34 lines · Hans de Goede
Hi,
Quoted 31 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.
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.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
I started looking at this patch because of the phoronix' news item on it.
First of all I want to say that it is great that AMD is working on getting the Sensor Fusion Hub supported on Linux and that you are working on a driver for this.
Thanks for the valuable input.
Quoted 105 lines
Quoted 81 lines
But, I've taken a quick look, mainly at the
"[PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)"
patch.AFAIK with the Intel ISH the sensor-hub itself is actually providing
HID descriptors and HID input reports.Looking at the AMD code, that does not seem to be the case, it seems
the values come directly from the AMD sensor-hub without being in any
HID specific form, e.g.:(quoted diff) +17
-0+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 */ + acc_input.common_property.report_id = report_id; + acc_input.common_property.sensor_state = + HID_USAGE_SENSOR_STATE_READ
Y_ENUM;(quoted diff) +2
-0+ acc_input.common_property.event_type = + HID_USAGE_SENSOR_EVENT_DATA_UPDATED
_ENUM;
+ acc_input.in_accel_x_value =
(int)sensor_virt_addr[0] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_y_value =
(int)sensor_virt_addr[1] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_z_value
= (int)sensor_virt_addr[2] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ memcpy(input_report,&acc_input,sizeof(acc_input));(quoted diff) +2
-0+ report_size = sizeof(acc_input); + break;And the descriptors are hardcoded in the driver so as to fake a HID device.
So going through the HID subsystem seems like an unnecessary detour,
which just makes things needlessly complex and harder to debug (and extend).The HID devices which the current patch-set is creating ultimately will result in a number of devices being created under
/sys/bus/iio/devicesAnd this are the devices which userspace uses to get the sensor data.
IMHO instead of going through the HID subsys the AMD Sensor Fusion Hub
driver should simply register 4 (*) iio-devices itself and directly pass the data through at the iio subsys level rather then going the long way around by creating a fake HID device which then gets attached to by the hid-sensor driver to ultimately create the same iio-devices.There are examples of e.g. various iio accel drivers under:
drivers/iio/accel/you could start with a simple driver supporting just the accelerometer bits and then extend things from there.Quoted 8 lines
Benjamin, Jiri, Jonathan, what is your take on this?
Hard to say without knowing AMD roadmap for that. If they intend to have an ISH-like approach in the end with reports and descriptors provided by the firmwares, then it makes sense to keep this architecture for the first revision of devices.
If not, then yes, this is probably overkill compared to what needs to be done.I suggested this approach to follow something like Chrome-OS EC based hub, but looks like in longer run this may come from firmware. That's why they may have decided.
Thanks,
SrinivasQuoted 8 lines
Sandeep, can you explain to us why you think using HID is the best way?
On a side note, I don't necessarily like patch 4/5 with the debugfs interface. It's adding a kernel API for no gain, and we should already
have the debug API available in the various subsystems involved.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Cheers,
BenjaminYes today, the HID Reports are getting generated in driver. But, we would like to have HID based driver as we may go for HID based firmware in future . Hence keeping that in mind current AMD SFH design.
So, kindly consider our design w.r.t HID for this patch series.
OK, that's good enough for me. Jiri, are you fine with that too?
Quoted 3 lines
For the debugfs part,currently it is really handy for us to debug raw values coming from firmware.But if guys feel that it is not necessary, we can remove it.
2 problems here:
- patch 3/5 references this debugfs interface which is only added in 4/5.
- you are creating a new sysfs set of file for debug purpose only, but as soon as we start shipping those, some other people will find it more convenient to use that directly instead or IIO, and you won't be able to change anything there.
So I would strongly advocate against having this debugfs, and suggest you to:
- either keep this debugfs as a downstream patch
- either play with eBPF or kprobes to retrieve the same information without changing the kernel.
For reference, I recently tried to replicate the hidraw functionality with eBPF[0] without changing the kernel code, and it was working. Well, there was no filtering on the source of the HID event, but still, I got the same data directly from the kernel just by adding instrumentation in a couple of functions.
Cheers,
Benjamin
[0] https://gitlab.freedesktop.org/bentiss/hid-tools/snippets/875
Hi
Quoted 177 lines · Benjamin Tissoires
Quoted 154 lines · Nehal-bakulchandra
Hi
Quoted 39 lines · Srinivas Pandruvada
Quoted 38 lines · Benjamin Tissoires
Hi,
Quoted 34 lines · Hans de Goede
Hi,
Quoted 31 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.
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.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
I started looking at this patch because of the phoronix' news item on it.
First of all I want to say that it is great that AMD is working on getting the Sensor Fusion Hub supported on Linux and that you are working on a driver for this.
Thanks for the valuable input.
Quoted 105 lines
Quoted 81 lines
But, I've taken a quick look, mainly at the
"[PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion Hub (SFH)"
patch.AFAIK with the Intel ISH the sensor-hub itself is actually providing
HID descriptors and HID input reports.Looking at the AMD code, that does not seem to be the case, it seems
the values come directly from the AMD sensor-hub without being in any
HID specific form, e.g.:(quoted diff) +17
-0+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 */ + acc_input.common_property.report_id = report_id; + acc_input.common_property.sensor_state = + HID_USAGE_SENSOR_STATE_READ
Y_ENUM;(quoted diff) +2
-0+ acc_input.common_property.event_type = + HID_USAGE_SENSOR_EVENT_DATA_UPDATED
_ENUM;
+ acc_input.in_accel_x_value =
(int)sensor_virt_addr[0] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_y_value =
(int)sensor_virt_addr[1] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ acc_input.in_accel_z_value
= (int)sensor_virt_addr[2] /
+AMD_SFH_FIRMWARE_MU
LTIPLIER;
+ memcpy(input_report,&acc_input,sizeof(acc_input));(quoted diff) +2
-0+ report_size = sizeof(acc_input); + break;And the descriptors are hardcoded in the driver so as to fake a HID device.
So going through the HID subsystem seems like an unnecessary detour,
which just makes things needlessly complex and harder to debug (and extend).The HID devices which the current patch-set is creating ultimately will result in a number of devices being created under
/sys/bus/iio/devicesAnd this are the devices which userspace uses to get the sensor data.
IMHO instead of going through the HID subsys the AMD Sensor Fusion Hub
driver should simply register 4 (*) iio-devices itself and directly pass the data through at the iio subsys level rather then going the long way around by creating a fake HID device which then gets attached to by the hid-sensor driver to ultimately create the same iio-devices.There are examples of e.g. various iio accel drivers under:
drivers/iio/accel/you could start with a simple driver supporting just the accelerometer bits and then extend things from there.Quoted 8 lines
Benjamin, Jiri, Jonathan, what is your take on this?
Hard to say without knowing AMD roadmap for that. If they intend to have an ISH-like approach in the end with reports and descriptors provided by the firmwares, then it makes sense to keep this architecture for the first revision of devices.
If not, then yes, this is probably overkill compared to what needs to be done.I suggested this approach to follow something like Chrome-OS EC based hub, but looks like in longer run this may come from firmware. That's why they may have decided.
Thanks,
SrinivasQuoted 8 lines
Sandeep, can you explain to us why you think using HID is the best way?
On a side note, I don't necessarily like patch 4/5 with the debugfs interface. It's adding a kernel API for no gain, and we should already
have the debug API available in the various subsystems involved.Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Cheers,
BenjaminYes today, the HID Reports are getting generated in driver. But, we would like to have HID based driver as we may go for HID based firmware in future . Hence keeping that in mind current AMD SFH design.
So, kindly consider our design w.r.t HID for this patch series.
OK, that's good enough for me. Jiri, are you fine with that too?
Quoted 2 lines
For the debugfs part,currently it is really handy for us to debug raw values coming from firmware.But if guys feel that it is not necessary, we can remove it.
2 problems here:
- patch 3/5 references this debugfs interface which is only added in 4/5.
- you are creating a new sysfs set of file for debug purpose only, but as soon as we start shipping those, some other people will find it more convenient to use that directly instead or IIO, and you won't be able to change anything there.So I would strongly advocate against having this debugfs, and suggest you to:
- either keep this debugfs as a downstream patch
- either play with eBPF or kprobes to retrieve the same information without changing the kernel.
Quoted 8 lines
For reference, I recently tried to replicate the hidraw functionality with eBPF[0] without changing the kernel code, and it was working. Well, there was no filtering on the source of the HID event, but still, I got the same data directly from the kernel just by adding instrumentation in a couple of functions.
Cheers,
Benjamin
If Jiri is Ok, then we will push the next patch as per suggestion here i.e. taking out debugfs.
Thanks
Nehal Shah
Quoted 1 line
Jiri Kosina
maintainerQuoted 12 lines · Nehal-bakulchandra
Quoted 12 lines
2 problems here:
- patch 3/5 references this debugfs interface which is only added in 4/5.
- you are creating a new sysfs set of file for debug purpose only, but as soon as we start shipping those, some other people will find it more convenient to use that directly instead or IIO, and you won't be able to change anything there.So I would strongly advocate against having this debugfs, and suggest you to:
- either keep this debugfs as a downstream patch
- either play with eBPF or kprobes to retrieve the same information without changing the kernel.
Quoted 5 lines
Quoted 5 lines
For reference, I recently tried to replicate the hidraw functionality with eBPF[0] without changing the kernel code, and it was working. Well, there was no filtering on the source of the HID event, but still, I got the same data directly from the kernel just by adding instrumentation in a couple of functions.
Wow. Complete eBPF supremacy is really coming shortly apparently :)
Quoted 2 lines
If Jiri is Ok, then we will push the next patch as per suggestion here i.e. taking out debugfs.
I agree with that. Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs