GNU Linux-libre 6.1.24-gnu
[releases.git] / drivers / hid / amd-sfh-hid / amd_sfh_pcie.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * AMD MP2 PCIe communication driver
4  * Copyright 2020-2021 Advanced Micro Devices, Inc.
5  * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
6  *          Sandeep Singh <Sandeep.singh@amd.com>
7  *          Basavaraj Natikar <Basavaraj.Natikar@amd.com>
8  */
9
10 #ifndef PCIE_MP2_AMD_H
11 #define PCIE_MP2_AMD_H
12
13 #include "amd_sfh_common.h"
14
15 /* MP2 C2P Message Registers */
16 #define AMD_C2P_MSG0    0x10500
17 #define AMD_C2P_MSG1    0x10504
18 #define AMD_C2P_MSG2    0x10508
19
20 /* MP2 P2C Message Registers */
21 #define AMD_P2C_MSG3    0x1068C /* Supported Sensors info */
22
23 #define V2_STATUS       0x2
24
25 #define HPD_IDX         16
26
27 #define SENSOR_DISCOVERY_STATUS_MASK            GENMASK(5, 3)
28 #define SENSOR_DISCOVERY_STATUS_SHIFT           3
29
30 /* SFH Command register */
31 union sfh_cmd_base {
32         u32 ul;
33         struct {
34                 u32 cmd_id : 8;
35                 u32 sensor_id : 8;
36                 u32 period : 16;
37         } s;
38         struct {
39                 u32 cmd_id : 4;
40                 u32 intr_disable : 1;
41                 u32 rsvd1 : 3;
42                 u32 length : 7;
43                 u32 mem_type : 1;
44                 u32 sensor_id : 8;
45                 u32 period : 8;
46         } cmd_v2;
47 };
48
49 union cmd_response {
50         u32 resp;
51         struct {
52                 u32 status      : 2;
53                 u32 out_in_c2p  : 1;
54                 u32 rsvd1       : 1;
55                 u32 response    : 4;
56                 u32 sub_cmd     : 8;
57                 u32 sensor_id   : 6;
58                 u32 rsvd2       : 10;
59         } response_v2;
60 };
61
62 union sfh_cmd_param {
63         u32 ul;
64         struct {
65                 u32 buf_layout : 2;
66                 u32 buf_length : 6;
67                 u32 rsvd : 24;
68         } s;
69 };
70
71 struct sfh_cmd_reg {
72         union sfh_cmd_base cmd_base;
73         union sfh_cmd_param cmd_param;
74         phys_addr_t phys_addr;
75 };
76
77 enum sensor_idx {
78         accel_idx = 0,
79         gyro_idx = 1,
80         mag_idx = 2,
81         als_idx = 19
82 };
83
84 enum mem_use_type {
85         USE_DRAM,
86         USE_C2P_REG,
87 };
88
89 struct hpd_status {
90         union {
91                 struct {
92                         u32 human_presence_report : 4;
93                         u32 human_presence_actual : 4;
94                         u32 probablity            : 8;
95                         u32 object_distance       : 16;
96                 } shpd;
97                 u32 val;
98         };
99 };
100
101 int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id);
102 int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata);
103 int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
104 void amd_sfh_set_desc_ops(struct amd_mp2_ops *mp2_ops);
105
106 #endif