14f567b9fSSandeep Singh /* SPDX-License-Identifier: GPL-2.0-or-later */ 24f567b9fSSandeep Singh /* 34f567b9fSSandeep Singh * AMD MP2 PCIe communication driver 44f567b9fSSandeep Singh * Copyright 2020 Advanced Micro Devices, Inc. 54f567b9fSSandeep Singh * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> 64f567b9fSSandeep Singh * Sandeep Singh <Sandeep.singh@amd.com> 74f567b9fSSandeep Singh */ 84f567b9fSSandeep Singh 94f567b9fSSandeep Singh #ifndef PCIE_MP2_AMD_H 104f567b9fSSandeep Singh #define PCIE_MP2_AMD_H 114f567b9fSSandeep Singh 124f567b9fSSandeep Singh #include <linux/pci.h> 134f567b9fSSandeep Singh 144f567b9fSSandeep Singh #define PCI_DEVICE_ID_AMD_MP2 0x15E4 154f567b9fSSandeep Singh 164f567b9fSSandeep Singh #define ENABLE_SENSOR 1 174f567b9fSSandeep Singh #define DISABLE_SENSOR 2 184f567b9fSSandeep Singh #define STOP_ALL_SENSORS 8 194f567b9fSSandeep Singh 204f567b9fSSandeep Singh /* MP2 C2P Message Registers */ 214f567b9fSSandeep Singh #define AMD_C2P_MSG0 0x10500 224f567b9fSSandeep Singh #define AMD_C2P_MSG1 0x10504 234f567b9fSSandeep Singh #define AMD_C2P_MSG2 0x10508 244f567b9fSSandeep Singh 25*f264481aSBasavaraj Natikar #define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4)) 26*f264481aSBasavaraj Natikar 274f567b9fSSandeep Singh /* MP2 P2C Message Registers */ 284f567b9fSSandeep Singh #define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */ 294f567b9fSSandeep Singh 30*f264481aSBasavaraj Natikar #define V2_STATUS 0x2 31*f264481aSBasavaraj Natikar 324f567b9fSSandeep Singh /* SFH Command register */ 334f567b9fSSandeep Singh union sfh_cmd_base { 344f567b9fSSandeep Singh u32 ul; 354f567b9fSSandeep Singh struct { 364f567b9fSSandeep Singh u32 cmd_id : 8; 374f567b9fSSandeep Singh u32 sensor_id : 8; 384f567b9fSSandeep Singh u32 period : 16; 394f567b9fSSandeep Singh } s; 40*f264481aSBasavaraj Natikar struct { 41*f264481aSBasavaraj Natikar u32 cmd_id : 4; 42*f264481aSBasavaraj Natikar u32 intr_enable : 1; 43*f264481aSBasavaraj Natikar u32 rsvd1 : 3; 44*f264481aSBasavaraj Natikar u32 length : 7; 45*f264481aSBasavaraj Natikar u32 mem_type : 1; 46*f264481aSBasavaraj Natikar u32 sensor_id : 8; 47*f264481aSBasavaraj Natikar u32 period : 8; 48*f264481aSBasavaraj Natikar } cmd_v2; 494f567b9fSSandeep Singh }; 504f567b9fSSandeep Singh 514f567b9fSSandeep Singh union sfh_cmd_param { 524f567b9fSSandeep Singh u32 ul; 534f567b9fSSandeep Singh struct { 544f567b9fSSandeep Singh u32 buf_layout : 2; 554f567b9fSSandeep Singh u32 buf_length : 6; 564f567b9fSSandeep Singh u32 rsvd : 24; 574f567b9fSSandeep Singh } s; 584f567b9fSSandeep Singh }; 594f567b9fSSandeep Singh 604f567b9fSSandeep Singh struct sfh_cmd_reg { 614f567b9fSSandeep Singh union sfh_cmd_base cmd_base; 624f567b9fSSandeep Singh union sfh_cmd_param cmd_param; 634f567b9fSSandeep Singh phys_addr_t phys_addr; 644f567b9fSSandeep Singh }; 654f567b9fSSandeep Singh 664f567b9fSSandeep Singh enum sensor_idx { 674f567b9fSSandeep Singh accel_idx = 0, 684f567b9fSSandeep Singh gyro_idx = 1, 694f567b9fSSandeep Singh mag_idx = 2, 704f567b9fSSandeep Singh als_idx = 19 714f567b9fSSandeep Singh }; 724f567b9fSSandeep Singh 734f567b9fSSandeep Singh struct amd_mp2_dev { 744f567b9fSSandeep Singh struct pci_dev *pdev; 754f567b9fSSandeep Singh struct amdtp_cl_data *cl_data; 764f567b9fSSandeep Singh void __iomem *mmio; 77*f264481aSBasavaraj Natikar const struct amd_mp2_ops *mp2_ops; 78*f264481aSBasavaraj Natikar /* mp2 active control status */ 79*f264481aSBasavaraj Natikar u32 mp2_acs; 804f567b9fSSandeep Singh }; 814f567b9fSSandeep Singh 824f567b9fSSandeep Singh struct amd_mp2_sensor_info { 834f567b9fSSandeep Singh u8 sensor_idx; 844f567b9fSSandeep Singh u32 period; 85de30491eSArnd Bergmann dma_addr_t dma_address; 864f567b9fSSandeep Singh }; 874f567b9fSSandeep Singh 88*f264481aSBasavaraj Natikar enum mem_use_type { 89*f264481aSBasavaraj Natikar USE_DRAM, 90*f264481aSBasavaraj Natikar USE_C2P_REG, 91*f264481aSBasavaraj Natikar }; 92*f264481aSBasavaraj Natikar 934f567b9fSSandeep Singh void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info); 944f567b9fSSandeep Singh void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx); 954f567b9fSSandeep Singh void amd_stop_all_sensors(struct amd_mp2_dev *privdata); 964f567b9fSSandeep Singh int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id); 974f567b9fSSandeep Singh int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata); 984f567b9fSSandeep Singh int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata); 99*f264481aSBasavaraj Natikar 100*f264481aSBasavaraj Natikar struct amd_mp2_ops { 101*f264481aSBasavaraj Natikar void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info); 102*f264481aSBasavaraj Natikar void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx); 103*f264481aSBasavaraj Natikar void (*stop_all)(struct amd_mp2_dev *privdata); 104*f264481aSBasavaraj Natikar }; 1054f567b9fSSandeep Singh #endif 106