xref: /linux/drivers/hid/amd-sfh-hid/amd_sfh_common.h (revision 2105e8e00da4673266e217653292fef6acefde03)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * AMD MP2 common macros and structures
4  *
5  * Copyright (c) 2022, Advanced Micro Devices, Inc.
6  * All Rights Reserved.
7  *
8  * Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
9  */
10 #ifndef AMD_SFH_COMMON_H
11 #define AMD_SFH_COMMON_H
12 
13 #include <linux/pci.h>
14 #include "amd_sfh_hid.h"
15 
16 #define PCI_DEVICE_ID_AMD_MP2		0x15E4
17 #define PCI_DEVICE_ID_AMD_MP2_1_1	0x164A
18 
19 #define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
20 #define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4))
21 
22 #define SENSOR_ENABLED			4
23 #define SENSOR_DISABLED			5
24 
25 #define AMD_SFH_IDLE_LOOP		200
26 
27 enum cmd_id {
28 	NO_OP,
29 	ENABLE_SENSOR,
30 	DISABLE_SENSOR,
31 	STOP_ALL_SENSORS = 8,
32 };
33 
34 struct amd_mp2_sensor_info {
35 	u8 sensor_idx;
36 	u32 period;
37 	dma_addr_t dma_address;
38 };
39 
40 struct sfh_dev_status {
41 	bool is_hpd_present;
42 	bool is_als_present;
43 };
44 
45 struct amd_mp2_dev {
46 	struct pci_dev *pdev;
47 	struct amdtp_cl_data *cl_data;
48 	void __iomem *mmio;
49 	void __iomem *vsbase;
50 	const struct amd_sfh1_1_ops *sfh1_1_ops;
51 	struct amd_mp2_ops *mp2_ops;
52 	struct amd_input_data in_data;
53 	/* mp2 active control status */
54 	u32 mp2_acs;
55 	struct sfh_dev_status dev_en;
56 	struct work_struct work;
57 	u8 init_done;
58 };
59 
60 struct amd_mp2_ops {
61 	void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
62 	void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx);
63 	void (*stop_all)(struct amd_mp2_dev *privdata);
64 	int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
65 	void (*clear_intr)(struct amd_mp2_dev *privdata);
66 	int (*init_intr)(struct amd_mp2_dev *privdata);
67 	int (*discovery_status)(struct amd_mp2_dev *privdata);
68 	void (*suspend)(struct amd_mp2_dev *mp2);
69 	void (*resume)(struct amd_mp2_dev *mp2);
70 	void (*remove)(void *privdata);
71 	int (*get_rep_desc)(int sensor_idx, u8 rep_desc[]);
72 	u32 (*get_desc_sz)(int sensor_idx, int descriptor_name);
73 	u8 (*get_feat_rep)(int sensor_idx, int report_id, u8 *feature_report);
74 	u8 (*get_in_rep)(u8 current_index, int sensor_idx, int report_id,
75 			 struct amd_input_data *in_data);
76 };
77 
78 void amd_sfh_work(struct work_struct *work);
79 void amd_sfh_work_buffer(struct work_struct *work);
80 void amd_sfh_clear_intr_v2(struct amd_mp2_dev *privdata);
81 int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata);
82 void amd_sfh_clear_intr(struct amd_mp2_dev *privdata);
83 int amd_sfh_irq_init(struct amd_mp2_dev *privdata);
84 #endif
85