xref: /OK3568_Linux_fs/kernel/drivers/tty/hvc/hvc_irq.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright IBM Corp. 2001,2008
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This file contains the IRQ specific code for hvc_console
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/interrupt.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include "hvc_console.h"
12*4882a593Smuzhiyun 
hvc_handle_interrupt(int irq,void * dev_instance)13*4882a593Smuzhiyun static irqreturn_t hvc_handle_interrupt(int irq, void *dev_instance)
14*4882a593Smuzhiyun {
15*4882a593Smuzhiyun 	/* if hvc_poll request a repoll, then kick the hvcd thread */
16*4882a593Smuzhiyun 	if (hvc_poll(dev_instance))
17*4882a593Smuzhiyun 		hvc_kick();
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun 	/*
20*4882a593Smuzhiyun 	 * We're safe to always return IRQ_HANDLED as the hvcd thread will
21*4882a593Smuzhiyun 	 * iterate through each hvc_struct.
22*4882a593Smuzhiyun 	 */
23*4882a593Smuzhiyun 	return IRQ_HANDLED;
24*4882a593Smuzhiyun }
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun  * For IRQ based systems these callbacks can be used
28*4882a593Smuzhiyun  */
notifier_add_irq(struct hvc_struct * hp,int irq)29*4882a593Smuzhiyun int notifier_add_irq(struct hvc_struct *hp, int irq)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun 	int rc;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	if (!irq) {
34*4882a593Smuzhiyun 		hp->irq_requested = 0;
35*4882a593Smuzhiyun 		return 0;
36*4882a593Smuzhiyun 	}
37*4882a593Smuzhiyun 	rc = request_irq(irq, hvc_handle_interrupt, hp->flags,
38*4882a593Smuzhiyun 			"hvc_console", hp);
39*4882a593Smuzhiyun 	if (!rc)
40*4882a593Smuzhiyun 		hp->irq_requested = 1;
41*4882a593Smuzhiyun 	return rc;
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun 
notifier_del_irq(struct hvc_struct * hp,int irq)44*4882a593Smuzhiyun void notifier_del_irq(struct hvc_struct *hp, int irq)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun 	if (!hp->irq_requested)
47*4882a593Smuzhiyun 		return;
48*4882a593Smuzhiyun 	free_irq(irq, hp);
49*4882a593Smuzhiyun 	hp->irq_requested = 0;
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun 
notifier_hangup_irq(struct hvc_struct * hp,int irq)52*4882a593Smuzhiyun void notifier_hangup_irq(struct hvc_struct *hp, int irq)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	notifier_del_irq(hp, irq);
55*4882a593Smuzhiyun }
56