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