1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * AMD MP2 Sensors transport driver
4  *
5  * Copyright 2020-2021 Advanced Micro Devices, Inc.
6  * Authors: Nehal Bakulchandra Shah <Nehal-bakulchandra.shah@amd.com>
7  *	    Sandeep Singh <sandeep.singh@amd.com>
8  *	    Basavaraj Natikar <Basavaraj.Natikar@amd.com>
9  */
10 
11 #ifndef AMDSFH_HID_H
12 #define AMDSFH_HID_H
13 
14 #define MAX_HID_DEVICES		5
15 #define BUS_AMD_AMDTP		0x20
16 #define AMD_SFH_HID_VENDOR	0x1022
17 #define AMD_SFH_HID_PRODUCT	0x0001
18 
19 struct amd_input_data {
20 	u32 *sensor_virt_addr[MAX_HID_DEVICES];
21 	u8 *input_report[MAX_HID_DEVICES];
22 };
23 
24 struct amdtp_cl_data {
25 	u8 init_done;
26 	u32 cur_hid_dev;
27 	u32 hid_dev_count;
28 	u32 num_hid_devices;
29 	struct device_info *hid_devices;
30 	u8  *report_descr[MAX_HID_DEVICES];
31 	int report_descr_sz[MAX_HID_DEVICES];
32 	struct hid_device *hid_sensor_hubs[MAX_HID_DEVICES];
33 	u8 *hid_descr[MAX_HID_DEVICES];
34 	int hid_descr_size[MAX_HID_DEVICES];
35 	phys_addr_t phys_addr_base;
36 	dma_addr_t sensor_dma_addr[MAX_HID_DEVICES];
37 	u32 sensor_sts[MAX_HID_DEVICES];
38 	u32 sensor_requested_cnt[MAX_HID_DEVICES];
39 	u8 report_type[MAX_HID_DEVICES];
40 	u8 report_id[MAX_HID_DEVICES];
41 	u8 sensor_idx[MAX_HID_DEVICES];
42 	u8 *feature_report[MAX_HID_DEVICES];
43 	u8 request_done[MAX_HID_DEVICES];
44 	struct amd_input_data *in_data;
45 	struct delayed_work work;
46 	struct delayed_work work_buffer;
47 };
48 
49 /**
50  * struct amdtp_hid_data - Per instance HID data
51  * @index:		Device index in the order of enumeration
52  * @request_done:	Get Feature/Input report complete flag
53  *			used during get/set request from hid core
54  * @cli_data:		Link to the client instance
55  * @hid_wait:		Completion waitq
56  *
57  * Used to tie hid->driver data to driver client instance
58  */
59 struct amdtp_hid_data {
60 	int index;
61 	struct amdtp_cl_data *cli_data;
62 	wait_queue_head_t hid_wait;
63 };
64 
65 /* Interface functions between HID LL driver and AMD SFH client */
66 void hid_amdtp_set_feature(struct hid_device *hid, char *buf, u32 len, int report_id);
67 void hid_amdtp_get_report(struct hid_device *hid, int report_id, int report_type);
68 int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data);
69 void amdtp_hid_remove(struct amdtp_cl_data *cli_data);
70 int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type);
71 void amd_sfh_set_report(struct hid_device *hid, int report_id, int report_type);
72 void amdtp_hid_wakeup(struct hid_device *hid);
73 u8 get_input_report(u8 current_index, int sensor_idx, int report_id,
74 		    struct amd_input_data *in_data);
75 #endif
76