1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * AMD MP2 PCIe communication driver
4  * Copyright 2020 Advanced Micro Devices, Inc.
5  * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
6  *	    Sandeep Singh <Sandeep.singh@amd.com>
7  */
8 
9 #ifndef PCIE_MP2_AMD_H
10 #define PCIE_MP2_AMD_H
11 
12 #include <linux/pci.h>
13 #include "amd_sfh_hid.h"
14 
15 #define PCI_DEVICE_ID_AMD_MP2	0x15E4
16 
17 #define ENABLE_SENSOR		1
18 #define DISABLE_SENSOR		2
19 #define STOP_ALL_SENSORS	8
20 
21 /* MP2 C2P Message Registers */
22 #define AMD_C2P_MSG0	0x10500
23 #define AMD_C2P_MSG1	0x10504
24 #define AMD_C2P_MSG2	0x10508
25 
26 #define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
27 
28 /* MP2 P2C Message Registers */
29 #define AMD_P2C_MSG3	0x1068C /* Supported Sensors info */
30 
31 #define V2_STATUS	0x2
32 
33 #define HPD_IDX		16
34 
35 /* SFH Command register */
36 union sfh_cmd_base {
37 	u32 ul;
38 	struct {
39 		u32 cmd_id : 8;
40 		u32 sensor_id : 8;
41 		u32 period : 16;
42 	} s;
43 	struct {
44 		u32 cmd_id : 4;
45 		u32 intr_enable : 1;
46 		u32 rsvd1 : 3;
47 		u32 length : 7;
48 		u32 mem_type : 1;
49 		u32 sensor_id : 8;
50 		u32 period : 8;
51 	} cmd_v2;
52 };
53 
54 union sfh_cmd_param {
55 	u32 ul;
56 	struct {
57 		u32 buf_layout : 2;
58 		u32 buf_length : 6;
59 		u32 rsvd : 24;
60 	} s;
61 };
62 
63 struct sfh_cmd_reg {
64 	union sfh_cmd_base cmd_base;
65 	union sfh_cmd_param cmd_param;
66 	phys_addr_t phys_addr;
67 };
68 
69 enum sensor_idx {
70 	accel_idx = 0,
71 	gyro_idx = 1,
72 	mag_idx = 2,
73 	als_idx = 19
74 };
75 
76 struct amd_mp2_dev {
77 	struct pci_dev *pdev;
78 	struct amdtp_cl_data *cl_data;
79 	void __iomem *mmio;
80 	const struct amd_mp2_ops *mp2_ops;
81 	struct amd_input_data in_data;
82 	/* mp2 active control status */
83 	u32 mp2_acs;
84 };
85 
86 struct amd_mp2_sensor_info {
87 	u8 sensor_idx;
88 	u32 period;
89 	dma_addr_t dma_address;
90 };
91 
92 enum mem_use_type {
93 	USE_DRAM,
94 	USE_C2P_REG,
95 };
96 
97 struct hpd_status {
98 	union {
99 		struct {
100 			u32 human_presence_report : 4;
101 			u32 human_presence_actual : 4;
102 			u32 probablity		  : 8;
103 			u32 object_distance       : 16;
104 		} shpd;
105 		u32 val;
106 	};
107 };
108 
109 void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
110 void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx);
111 void amd_stop_all_sensors(struct amd_mp2_dev *privdata);
112 int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id);
113 int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata);
114 int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
115 
116 struct amd_mp2_ops {
117 	 void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
118 	 void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx);
119 	 void (*stop_all)(struct amd_mp2_dev *privdata);
120 };
121 #endif
122