blob: 1ff6f83cb6fd18e7abb7ba22701a2d554ec84133 [file] [log] [blame]
Sandeep Singh4f567b92020-10-10 01:31:36 +05301/* 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>
Basavaraj Natikar0aad9c92021-06-18 13:48:37 +053013#include "amd_sfh_hid.h"
Sandeep Singh4f567b92020-10-10 01:31:36 +053014
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
Basavaraj Natikarf2644812021-06-18 13:48:36 +053026#define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
Basavaraj Natikar173709f2021-08-02 19:33:38 +053027#define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4))
Basavaraj Natikarf2644812021-06-18 13:48:36 +053028
Sandeep Singh4f567b92020-10-10 01:31:36 +053029/* MP2 P2C Message Registers */
30#define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */
31
Basavaraj Natikarf2644812021-06-18 13:48:36 +053032#define V2_STATUS 0x2
33
Basavaraj Natikar173709f2021-08-02 19:33:38 +053034#define SENSOR_ENABLED 4
35#define SENSOR_DISABLED 5
36
Basavaraj Natikar24a31ea2021-06-18 13:48:38 +053037#define HPD_IDX 16
38
Basavaraj Natikar0873d1a2021-08-02 19:33:40 +053039#define AMD_SFH_IDLE_LOOP 200
40
Sandeep Singh4f567b92020-10-10 01:31:36 +053041/* SFH Command register */
42union sfh_cmd_base {
43 u32 ul;
44 struct {
45 u32 cmd_id : 8;
46 u32 sensor_id : 8;
47 u32 period : 16;
48 } s;
Basavaraj Natikarf2644812021-06-18 13:48:36 +053049 struct {
50 u32 cmd_id : 4;
51 u32 intr_enable : 1;
52 u32 rsvd1 : 3;
53 u32 length : 7;
54 u32 mem_type : 1;
55 u32 sensor_id : 8;
56 u32 period : 8;
57 } cmd_v2;
Sandeep Singh4f567b92020-10-10 01:31:36 +053058};
59
Basavaraj Natikar173709f2021-08-02 19:33:38 +053060union cmd_response {
61 u32 resp;
62 struct {
63 u32 status : 2;
64 u32 out_in_c2p : 1;
65 u32 rsvd1 : 1;
66 u32 response : 4;
67 u32 sub_cmd : 8;
68 u32 sensor_id : 6;
69 u32 rsvd2 : 10;
70 } response_v2;
71};
72
Sandeep Singh4f567b92020-10-10 01:31:36 +053073union sfh_cmd_param {
74 u32 ul;
75 struct {
76 u32 buf_layout : 2;
77 u32 buf_length : 6;
78 u32 rsvd : 24;
79 } s;
80};
81
82struct sfh_cmd_reg {
83 union sfh_cmd_base cmd_base;
84 union sfh_cmd_param cmd_param;
85 phys_addr_t phys_addr;
86};
87
88enum sensor_idx {
89 accel_idx = 0,
90 gyro_idx = 1,
91 mag_idx = 2,
92 als_idx = 19
93};
94
95struct amd_mp2_dev {
96 struct pci_dev *pdev;
97 struct amdtp_cl_data *cl_data;
98 void __iomem *mmio;
Basavaraj Natikarf2644812021-06-18 13:48:36 +053099 const struct amd_mp2_ops *mp2_ops;
Basavaraj Natikar0aad9c92021-06-18 13:48:37 +0530100 struct amd_input_data in_data;
Basavaraj Natikarf2644812021-06-18 13:48:36 +0530101 /* mp2 active control status */
102 u32 mp2_acs;
Sandeep Singh4f567b92020-10-10 01:31:36 +0530103};
104
105struct amd_mp2_sensor_info {
106 u8 sensor_idx;
107 u32 period;
Arnd Bergmannde304912021-01-03 14:53:55 +0100108 dma_addr_t dma_address;
Sandeep Singh4f567b92020-10-10 01:31:36 +0530109};
110
Basavaraj Natikarf2644812021-06-18 13:48:36 +0530111enum mem_use_type {
112 USE_DRAM,
113 USE_C2P_REG,
114};
115
Basavaraj Natikar24a31ea2021-06-18 13:48:38 +0530116struct hpd_status {
117 union {
118 struct {
119 u32 human_presence_report : 4;
120 u32 human_presence_actual : 4;
121 u32 probablity : 8;
122 u32 object_distance : 16;
123 } shpd;
124 u32 val;
125 };
126};
127
Sandeep Singh4f567b92020-10-10 01:31:36 +0530128void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
129void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx);
130void amd_stop_all_sensors(struct amd_mp2_dev *privdata);
131int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id);
132int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata);
133int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
Basavaraj Natikar0873d1a2021-08-02 19:33:40 +0530134u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
135void amd_mp2_suspend(struct amd_mp2_dev *mp2);
136void amd_mp2_resume(struct amd_mp2_dev *mp2);
Basavaraj Natikarf2644812021-06-18 13:48:36 +0530137
138struct amd_mp2_ops {
139 void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
140 void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx);
141 void (*stop_all)(struct amd_mp2_dev *privdata);
Basavaraj Natikar173709f2021-08-02 19:33:38 +0530142 int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
Basavaraj Natikarf2644812021-06-18 13:48:36 +0530143};
Sandeep Singh4f567b92020-10-10 01:31:36 +0530144#endif