@@ -59,6 +59,7 @@ struct aspeed_lpc_snoop_model_data {
59
59
};
60
60
61
61
struct aspeed_lpc_snoop_channel {
62
+ bool enabled ;
62
63
struct kfifo fifo ;
63
64
wait_queue_head_t wq ;
64
65
struct miscdevice miscdev ;
@@ -191,6 +192,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
191
192
const struct aspeed_lpc_snoop_model_data * model_data =
192
193
of_device_get_match_data (dev );
193
194
195
+ if (WARN_ON (lpc_snoop -> chan [channel ].enabled ))
196
+ return - EBUSY ;
197
+
194
198
init_waitqueue_head (& lpc_snoop -> chan [channel ].wq );
195
199
/* Create FIFO datastructure */
196
200
rc = kfifo_alloc (& lpc_snoop -> chan [channel ].fifo ,
@@ -237,6 +241,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
237
241
regmap_update_bits (lpc_snoop -> regmap , HICRB ,
238
242
hicrb_en , hicrb_en );
239
243
244
+ lpc_snoop -> chan [channel ].enabled = true;
245
+
240
246
return 0 ;
241
247
242
248
err_misc_deregister :
@@ -249,6 +255,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
249
255
static void aspeed_lpc_disable_snoop (struct aspeed_lpc_snoop * lpc_snoop ,
250
256
int channel )
251
257
{
258
+ if (!lpc_snoop -> chan [channel ].enabled )
259
+ return ;
260
+
252
261
switch (channel ) {
253
262
case 0 :
254
263
regmap_update_bits (lpc_snoop -> regmap , HICR5 ,
@@ -264,6 +273,8 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
264
273
return ;
265
274
}
266
275
276
+ lpc_snoop -> chan [channel ].enabled = false;
277
+ /* Consider improving safety wrt concurrent reader(s) */
267
278
misc_deregister (& lpc_snoop -> chan [channel ].miscdev );
268
279
kfifo_free (& lpc_snoop -> chan [channel ].fifo );
269
280
}
0 commit comments