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> 130aad9c95SBasavaraj Natikar #include "amd_sfh_hid.h" 144f567b9fSSandeep Singh 154f567b9fSSandeep Singh #define PCI_DEVICE_ID_AMD_MP2 0x15E4 164f567b9fSSandeep Singh 174f567b9fSSandeep Singh #define ENABLE_SENSOR 1 184f567b9fSSandeep Singh #define DISABLE_SENSOR 2 194f567b9fSSandeep Singh #define STOP_ALL_SENSORS 8 204f567b9fSSandeep Singh 214f567b9fSSandeep Singh /* MP2 C2P Message Registers */ 224f567b9fSSandeep Singh #define AMD_C2P_MSG0 0x10500 234f567b9fSSandeep Singh #define AMD_C2P_MSG1 0x10504 244f567b9fSSandeep Singh #define AMD_C2P_MSG2 0x10508 254f567b9fSSandeep Singh 26f264481aSBasavaraj Natikar #define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4)) 27*173709f5SBasavaraj Natikar #define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4)) 28f264481aSBasavaraj Natikar 294f567b9fSSandeep Singh /* MP2 P2C Message Registers */ 304f567b9fSSandeep Singh #define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */ 314f567b9fSSandeep Singh 32f264481aSBasavaraj Natikar #define V2_STATUS 0x2 33f264481aSBasavaraj Natikar 34*173709f5SBasavaraj Natikar #define SENSOR_ENABLED 4 35*173709f5SBasavaraj Natikar #define SENSOR_DISABLED 5 36*173709f5SBasavaraj Natikar 3724a31ea9SBasavaraj Natikar #define HPD_IDX 16 3824a31ea9SBasavaraj Natikar 394f567b9fSSandeep Singh /* SFH Command register */ 404f567b9fSSandeep Singh union sfh_cmd_base { 414f567b9fSSandeep Singh u32 ul; 424f567b9fSSandeep Singh struct { 434f567b9fSSandeep Singh u32 cmd_id : 8; 444f567b9fSSandeep Singh u32 sensor_id : 8; 454f567b9fSSandeep Singh u32 period : 16; 464f567b9fSSandeep Singh } s; 47f264481aSBasavaraj Natikar struct { 48f264481aSBasavaraj Natikar u32 cmd_id : 4; 49f264481aSBasavaraj Natikar u32 intr_enable : 1; 50f264481aSBasavaraj Natikar u32 rsvd1 : 3; 51f264481aSBasavaraj Natikar u32 length : 7; 52f264481aSBasavaraj Natikar u32 mem_type : 1; 53f264481aSBasavaraj Natikar u32 sensor_id : 8; 54f264481aSBasavaraj Natikar u32 period : 8; 55f264481aSBasavaraj Natikar } cmd_v2; 564f567b9fSSandeep Singh }; 574f567b9fSSandeep Singh 58*173709f5SBasavaraj Natikar union cmd_response { 59*173709f5SBasavaraj Natikar u32 resp; 60*173709f5SBasavaraj Natikar struct { 61*173709f5SBasavaraj Natikar u32 status : 2; 62*173709f5SBasavaraj Natikar u32 out_in_c2p : 1; 63*173709f5SBasavaraj Natikar u32 rsvd1 : 1; 64*173709f5SBasavaraj Natikar u32 response : 4; 65*173709f5SBasavaraj Natikar u32 sub_cmd : 8; 66*173709f5SBasavaraj Natikar u32 sensor_id : 6; 67*173709f5SBasavaraj Natikar u32 rsvd2 : 10; 68*173709f5SBasavaraj Natikar } response_v2; 69*173709f5SBasavaraj Natikar }; 70*173709f5SBasavaraj Natikar 714f567b9fSSandeep Singh union sfh_cmd_param { 724f567b9fSSandeep Singh u32 ul; 734f567b9fSSandeep Singh struct { 744f567b9fSSandeep Singh u32 buf_layout : 2; 754f567b9fSSandeep Singh u32 buf_length : 6; 764f567b9fSSandeep Singh u32 rsvd : 24; 774f567b9fSSandeep Singh } s; 784f567b9fSSandeep Singh }; 794f567b9fSSandeep Singh 804f567b9fSSandeep Singh struct sfh_cmd_reg { 814f567b9fSSandeep Singh union sfh_cmd_base cmd_base; 824f567b9fSSandeep Singh union sfh_cmd_param cmd_param; 834f567b9fSSandeep Singh phys_addr_t phys_addr; 844f567b9fSSandeep Singh }; 854f567b9fSSandeep Singh 864f567b9fSSandeep Singh enum sensor_idx { 874f567b9fSSandeep Singh accel_idx = 0, 884f567b9fSSandeep Singh gyro_idx = 1, 894f567b9fSSandeep Singh mag_idx = 2, 904f567b9fSSandeep Singh als_idx = 19 914f567b9fSSandeep Singh }; 924f567b9fSSandeep Singh 934f567b9fSSandeep Singh struct amd_mp2_dev { 944f567b9fSSandeep Singh struct pci_dev *pdev; 954f567b9fSSandeep Singh struct amdtp_cl_data *cl_data; 964f567b9fSSandeep Singh void __iomem *mmio; 97f264481aSBasavaraj Natikar const struct amd_mp2_ops *mp2_ops; 980aad9c95SBasavaraj Natikar struct amd_input_data in_data; 99f264481aSBasavaraj Natikar /* mp2 active control status */ 100f264481aSBasavaraj Natikar u32 mp2_acs; 1014f567b9fSSandeep Singh }; 1024f567b9fSSandeep Singh 1034f567b9fSSandeep Singh struct amd_mp2_sensor_info { 1044f567b9fSSandeep Singh u8 sensor_idx; 1054f567b9fSSandeep Singh u32 period; 106de30491eSArnd Bergmann dma_addr_t dma_address; 1074f567b9fSSandeep Singh }; 1084f567b9fSSandeep Singh 109f264481aSBasavaraj Natikar enum mem_use_type { 110f264481aSBasavaraj Natikar USE_DRAM, 111f264481aSBasavaraj Natikar USE_C2P_REG, 112f264481aSBasavaraj Natikar }; 113f264481aSBasavaraj Natikar 11424a31ea9SBasavaraj Natikar struct hpd_status { 11524a31ea9SBasavaraj Natikar union { 11624a31ea9SBasavaraj Natikar struct { 11724a31ea9SBasavaraj Natikar u32 human_presence_report : 4; 11824a31ea9SBasavaraj Natikar u32 human_presence_actual : 4; 11924a31ea9SBasavaraj Natikar u32 probablity : 8; 12024a31ea9SBasavaraj Natikar u32 object_distance : 16; 12124a31ea9SBasavaraj Natikar } shpd; 12224a31ea9SBasavaraj Natikar u32 val; 12324a31ea9SBasavaraj Natikar }; 12424a31ea9SBasavaraj Natikar }; 12524a31ea9SBasavaraj Natikar 1264f567b9fSSandeep Singh void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info); 1274f567b9fSSandeep Singh void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx); 1284f567b9fSSandeep Singh void amd_stop_all_sensors(struct amd_mp2_dev *privdata); 1294f567b9fSSandeep Singh int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id); 1304f567b9fSSandeep Singh int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata); 1314f567b9fSSandeep Singh int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata); 132f264481aSBasavaraj Natikar 133f264481aSBasavaraj Natikar struct amd_mp2_ops { 134f264481aSBasavaraj Natikar void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info); 135f264481aSBasavaraj Natikar void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx); 136f264481aSBasavaraj Natikar void (*stop_all)(struct amd_mp2_dev *privdata); 137*173709f5SBasavaraj Natikar int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts); 138f264481aSBasavaraj Natikar }; 1394f567b9fSSandeep Singh #endif 140