18
18
#include "amd_sfh_pcie.h"
19
19
#include "amd_sfh_hid.h"
20
20
21
-
22
- struct request_list {
23
- struct hid_device * hid ;
24
- struct list_head list ;
25
- u8 report_id ;
26
- u8 sensor_idx ;
27
- u8 report_type ;
28
- u8 current_index ;
29
- };
30
-
31
- static struct request_list req_list ;
32
-
33
21
void amd_sfh_set_report (struct hid_device * hid , int report_id ,
34
22
int report_type )
35
23
{
@@ -50,6 +38,7 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type)
50
38
{
51
39
struct amdtp_hid_data * hid_data = hid -> driver_data ;
52
40
struct amdtp_cl_data * cli_data = hid_data -> cli_data ;
41
+ struct request_list * req_list = & cli_data -> req_list ;
53
42
int i ;
54
43
55
44
for (i = 0 ; i < cli_data -> num_hid_devices ; i ++ ) {
@@ -66,34 +55,39 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type)
66
55
new -> report_id = report_id ;
67
56
cli_data -> report_id [i ] = report_id ;
68
57
cli_data -> request_done [i ] = false;
69
- list_add (& new -> list , & req_list . list );
58
+ list_add (& new -> list , & req_list -> list );
70
59
break ;
71
60
}
72
61
}
73
62
schedule_delayed_work (& cli_data -> work , 0 );
74
63
return 0 ;
75
64
}
76
65
77
- static void amd_sfh_work (struct work_struct * work )
66
+ void amd_sfh_work (struct work_struct * work )
78
67
{
79
68
struct amdtp_cl_data * cli_data = container_of (work , struct amdtp_cl_data , work .work );
69
+ struct request_list * req_list = & cli_data -> req_list ;
80
70
struct amd_input_data * in_data = cli_data -> in_data ;
81
71
struct request_list * req_node ;
82
72
u8 current_index , sensor_index ;
73
+ struct amd_mp2_ops * mp2_ops ;
74
+ struct amd_mp2_dev * mp2 ;
83
75
u8 report_id , node_type ;
84
76
u8 report_size = 0 ;
85
77
86
- req_node = list_last_entry (& req_list . list , struct request_list , list );
78
+ req_node = list_last_entry (& req_list -> list , struct request_list , list );
87
79
list_del (& req_node -> list );
88
80
current_index = req_node -> current_index ;
89
81
sensor_index = req_node -> sensor_idx ;
90
82
report_id = req_node -> report_id ;
91
83
node_type = req_node -> report_type ;
92
84
kfree (req_node );
93
85
86
+ mp2 = container_of (in_data , struct amd_mp2_dev , in_data );
87
+ mp2_ops = mp2 -> mp2_ops ;
94
88
if (node_type == HID_FEATURE_REPORT ) {
95
- report_size = get_feature_report (sensor_index , report_id ,
96
- cli_data -> feature_report [current_index ]);
89
+ report_size = mp2_ops -> get_feat_rep (sensor_index , report_id ,
90
+ cli_data -> feature_report [current_index ]);
97
91
if (report_size )
98
92
hid_input_report (cli_data -> hid_sensor_hubs [current_index ],
99
93
cli_data -> report_type [current_index ],
@@ -102,7 +96,7 @@ static void amd_sfh_work(struct work_struct *work)
102
96
pr_err ("AMDSFH: Invalid report size\n" );
103
97
104
98
} else if (node_type == HID_INPUT_REPORT ) {
105
- report_size = get_input_report (current_index , sensor_index , report_id , in_data );
99
+ report_size = mp2_ops -> get_in_rep (current_index , sensor_index , report_id , in_data );
106
100
if (report_size )
107
101
hid_input_report (cli_data -> hid_sensor_hubs [current_index ],
108
102
cli_data -> report_type [current_index ],
@@ -115,33 +109,35 @@ static void amd_sfh_work(struct work_struct *work)
115
109
amdtp_hid_wakeup (cli_data -> hid_sensor_hubs [current_index ]);
116
110
}
117
111
118
- static void amd_sfh_work_buffer (struct work_struct * work )
112
+ void amd_sfh_work_buffer (struct work_struct * work )
119
113
{
120
114
struct amdtp_cl_data * cli_data = container_of (work , struct amdtp_cl_data , work_buffer .work );
121
115
struct amd_input_data * in_data = cli_data -> in_data ;
116
+ struct amd_mp2_dev * mp2 ;
122
117
u8 report_size ;
123
118
int i ;
124
119
125
120
for (i = 0 ; i < cli_data -> num_hid_devices ; i ++ ) {
126
121
if (cli_data -> sensor_sts [i ] == SENSOR_ENABLED ) {
127
- report_size = get_input_report
128
- (i , cli_data -> sensor_idx [i ], cli_data -> report_id [i ], in_data );
122
+ mp2 = container_of (in_data , struct amd_mp2_dev , in_data );
123
+ report_size = mp2 -> mp2_ops -> get_in_rep (i , cli_data -> sensor_idx [i ],
124
+ cli_data -> report_id [i ], in_data );
129
125
hid_input_report (cli_data -> hid_sensor_hubs [i ], HID_INPUT_REPORT ,
130
126
in_data -> input_report [i ], report_size , 0 );
131
127
}
132
128
}
133
129
schedule_delayed_work (& cli_data -> work_buffer , msecs_to_jiffies (AMD_SFH_IDLE_LOOP ));
134
130
}
135
131
136
- u32 amd_sfh_wait_for_response (struct amd_mp2_dev * mp2 , u8 sid , u32 sensor_sts )
132
+ static u32 amd_sfh_wait_for_response (struct amd_mp2_dev * mp2 , u8 sid , u32 sensor_sts )
137
133
{
138
134
if (mp2 -> mp2_ops -> response )
139
135
sensor_sts = mp2 -> mp2_ops -> response (mp2 , sid , sensor_sts );
140
136
141
137
return sensor_sts ;
142
138
}
143
139
144
- const char * get_sensor_name (int idx )
140
+ static const char * get_sensor_name (int idx )
145
141
{
146
142
switch (idx ) {
147
143
case accel_idx :
@@ -159,24 +155,82 @@ const char *get_sensor_name(int idx)
159
155
}
160
156
}
161
157
158
+ static void amd_sfh_resume (struct amd_mp2_dev * mp2 )
159
+ {
160
+ struct amdtp_cl_data * cl_data = mp2 -> cl_data ;
161
+ struct amd_mp2_sensor_info info ;
162
+ int i , status ;
163
+
164
+ for (i = 0 ; i < cl_data -> num_hid_devices ; i ++ ) {
165
+ if (cl_data -> sensor_sts [i ] == SENSOR_DISABLED ) {
166
+ info .period = AMD_SFH_IDLE_LOOP ;
167
+ info .sensor_idx = cl_data -> sensor_idx [i ];
168
+ info .dma_address = cl_data -> sensor_dma_addr [i ];
169
+ mp2 -> mp2_ops -> start (mp2 , info );
170
+ status = amd_sfh_wait_for_response
171
+ (mp2 , cl_data -> sensor_idx [i ], SENSOR_ENABLED );
172
+ if (status == SENSOR_ENABLED )
173
+ cl_data -> sensor_sts [i ] = SENSOR_ENABLED ;
174
+ dev_dbg (& mp2 -> pdev -> dev , "resume sid 0x%x (%s) status 0x%x\n" ,
175
+ cl_data -> sensor_idx [i ], get_sensor_name (cl_data -> sensor_idx [i ]),
176
+ cl_data -> sensor_sts [i ]);
177
+ }
178
+ }
179
+
180
+ schedule_delayed_work (& cl_data -> work_buffer , msecs_to_jiffies (AMD_SFH_IDLE_LOOP ));
181
+ amd_sfh_clear_intr (mp2 );
182
+ }
183
+
184
+ static void amd_sfh_suspend (struct amd_mp2_dev * mp2 )
185
+ {
186
+ struct amdtp_cl_data * cl_data = mp2 -> cl_data ;
187
+ int i , status ;
188
+
189
+ for (i = 0 ; i < cl_data -> num_hid_devices ; i ++ ) {
190
+ if (cl_data -> sensor_idx [i ] != HPD_IDX &&
191
+ cl_data -> sensor_sts [i ] == SENSOR_ENABLED ) {
192
+ mp2 -> mp2_ops -> stop (mp2 , cl_data -> sensor_idx [i ]);
193
+ status = amd_sfh_wait_for_response
194
+ (mp2 , cl_data -> sensor_idx [i ], SENSOR_DISABLED );
195
+ if (status != SENSOR_ENABLED )
196
+ cl_data -> sensor_sts [i ] = SENSOR_DISABLED ;
197
+ dev_dbg (& mp2 -> pdev -> dev , "suspend sid 0x%x (%s) status 0x%x\n" ,
198
+ cl_data -> sensor_idx [i ], get_sensor_name (cl_data -> sensor_idx [i ]),
199
+ cl_data -> sensor_sts [i ]);
200
+ }
201
+ }
202
+
203
+ cancel_delayed_work_sync (& cl_data -> work_buffer );
204
+ amd_sfh_clear_intr (mp2 );
205
+ }
206
+
162
207
int amd_sfh_hid_client_init (struct amd_mp2_dev * privdata )
163
208
{
164
209
struct amd_input_data * in_data = & privdata -> in_data ;
165
210
struct amdtp_cl_data * cl_data = privdata -> cl_data ;
211
+ struct amd_mp2_ops * mp2_ops = privdata -> mp2_ops ;
166
212
struct amd_mp2_sensor_info info ;
213
+ struct request_list * req_list ;
167
214
struct device * dev ;
168
215
u32 feature_report_size ;
169
216
u32 input_report_size ;
170
217
int rc , i , status ;
171
218
u8 cl_idx ;
172
219
220
+ req_list = & cl_data -> req_list ;
173
221
dev = & privdata -> pdev -> dev ;
222
+ amd_sfh_set_desc_ops (mp2_ops );
223
+
224
+ mp2_ops -> suspend = amd_sfh_suspend ;
225
+ mp2_ops -> resume = amd_sfh_resume ;
174
226
175
227
cl_data -> num_hid_devices = amd_mp2_get_sensor_num (privdata , & cl_data -> sensor_idx [0 ]);
228
+ if (cl_data -> num_hid_devices == 0 )
229
+ return - ENODEV ;
176
230
177
231
INIT_DELAYED_WORK (& cl_data -> work , amd_sfh_work );
178
232
INIT_DELAYED_WORK (& cl_data -> work_buffer , amd_sfh_work_buffer );
179
- INIT_LIST_HEAD (& req_list . list );
233
+ INIT_LIST_HEAD (& req_list -> list );
180
234
cl_data -> in_data = in_data ;
181
235
182
236
for (i = 0 ; i < cl_data -> num_hid_devices ; i ++ ) {
@@ -187,17 +241,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
187
241
cl_data -> sensor_requested_cnt [i ] = 0 ;
188
242
cl_data -> cur_hid_dev = i ;
189
243
cl_idx = cl_data -> sensor_idx [i ];
190
- cl_data -> report_descr_sz [i ] = get_descr_sz (cl_idx , descr_size );
244
+ cl_data -> report_descr_sz [i ] = mp2_ops -> get_desc_sz (cl_idx , descr_size );
191
245
if (!cl_data -> report_descr_sz [i ]) {
192
246
rc = - EINVAL ;
193
247
goto cleanup ;
194
248
}
195
- feature_report_size = get_descr_sz (cl_idx , feature_size );
249
+ feature_report_size = mp2_ops -> get_desc_sz (cl_idx , feature_size );
196
250
if (!feature_report_size ) {
197
251
rc = - EINVAL ;
198
252
goto cleanup ;
199
253
}
200
- input_report_size = get_descr_sz (cl_idx , input_size );
254
+ input_report_size = mp2_ops -> get_desc_sz (cl_idx , input_size );
201
255
if (!input_report_size ) {
202
256
rc = - EINVAL ;
203
257
goto cleanup ;
@@ -222,17 +276,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
222
276
rc = - ENOMEM ;
223
277
goto cleanup ;
224
278
}
225
- rc = get_report_descriptor (cl_idx , cl_data -> report_descr [i ]);
279
+ rc = mp2_ops -> get_rep_desc (cl_idx , cl_data -> report_descr [i ]);
226
280
if (rc )
227
281
return rc ;
228
- privdata -> mp2_ops -> start (privdata , info );
282
+ mp2_ops -> start (privdata , info );
229
283
status = amd_sfh_wait_for_response
230
284
(privdata , cl_data -> sensor_idx [i ], SENSOR_ENABLED );
231
285
if (status == SENSOR_ENABLED ) {
232
286
cl_data -> sensor_sts [i ] = SENSOR_ENABLED ;
233
287
rc = amdtp_hid_probe (cl_data -> cur_hid_dev , cl_data );
234
288
if (rc ) {
235
- privdata -> mp2_ops -> stop (privdata , cl_data -> sensor_idx [i ]);
289
+ mp2_ops -> stop (privdata , cl_data -> sensor_idx [i ]);
236
290
status = amd_sfh_wait_for_response
237
291
(privdata , cl_data -> sensor_idx [i ], SENSOR_DISABLED );
238
292
if (status != SENSOR_ENABLED )
@@ -248,8 +302,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
248
302
cl_data -> sensor_idx [i ], get_sensor_name (cl_data -> sensor_idx [i ]),
249
303
cl_data -> sensor_sts [i ]);
250
304
}
251
- if (privdata -> mp2_ops -> discovery_status &&
252
- privdata -> mp2_ops -> discovery_status (privdata ) == 0 ) {
305
+ if (mp2_ops -> discovery_status && mp2_ops -> discovery_status (privdata ) == 0 ) {
253
306
amd_sfh_hid_client_deinit (privdata );
254
307
for (i = 0 ; i < cl_data -> num_hid_devices ; i ++ ) {
255
308
devm_kfree (dev , cl_data -> feature_report [i ]);
0 commit comments