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 AMD_SFH_HID_VENDOR	0x1022
16 #define AMD_SFH_HID_PRODUCT	0x0001
17 
18 struct amd_input_data {
19 	u32 *sensor_virt_addr[MAX_HID_DEVICES];
20 	u8 *input_report[MAX_HID_DEVICES];
21 };
22 
23 struct amdtp_cl_data {
24 	u8 init_done;
25 	u32 cur_hid_dev;
26 	u32 hid_dev_count;
27 	u32 num_hid_devices;
28 	struct device_info *hid_devices;
29 	u8  *report_descr[MAX_HID_DEVICES];
30 	int report_descr_sz[MAX_HID_DEVICES];
31 	struct hid_device *hid_sensor_hubs[MAX_HID_DEVICES];
32 	u8 *hid_descr[MAX_HID_DEVICES];
33 	int hid_descr_size[MAX_HID_DEVICES];
34 	phys_addr_t phys_addr_base;
35 	dma_addr_t sensor_dma_addr[MAX_HID_DEVICES];
36 	u32 sensor_sts[MAX_HID_DEVICES];
37 	u32 sensor_requested_cnt[MAX_HID_DEVICES];
38 	u8 report_type[MAX_HID_DEVICES];
39 	u8 report_id[MAX_HID_DEVICES];
40 	u8 sensor_idx[MAX_HID_DEVICES];
41 	u8 *feature_report[MAX_HID_DEVICES];
42 	u8 request_done[MAX_HID_DEVICES];
43 	struct amd_input_data *in_data;
44 	struct delayed_work work;
45 	struct delayed_work work_buffer;
46 };
47 
48 /**
49  * struct amdtp_hid_data - Per instance HID data
50  * @index:		Device index in the order of enumeration
51  * @request_done:	Get Feature/Input report complete flag
52  *			used during get/set request from hid core
53  * @cli_data:		Link to the client instance
54  * @hid_wait:		Completion waitq
55  *
56  * Used to tie hid->driver data to driver client instance
57  */
58 struct amdtp_hid_data {
59 	int index;
60 	struct amdtp_cl_data *cli_data;
61 	wait_queue_head_t hid_wait;
62 };
63 
64 /* Interface functions between HID LL driver and AMD SFH client */
65 void hid_amdtp_set_feature(struct hid_device *hid, char *buf, u32 len, int report_id);
66 void hid_amdtp_get_report(struct hid_device *hid, int report_id, int report_type);
67 int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data);
68 void amdtp_hid_remove(struct amdtp_cl_data *cli_data);
69 int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type);
70 void amd_sfh_set_report(struct hid_device *hid, int report_id, int report_type);
71 void amdtp_hid_wakeup(struct hid_device *hid);
72 u8 get_input_report(u8 current_index, int sensor_idx, int report_id,
73 		    struct amd_input_data *in_data);
74 #endif
75