linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_fintek: fix the mismatched IRQ mode
@ 2016-05-27  2:02 Ji-Ze Hong (Peter Hong)
  2016-06-27 10:25 ` Ricardo Ribalda Delgado
  0 siblings, 1 reply; 3+ messages in thread
From: Ji-Ze Hong (Peter Hong) @ 2016-05-27  2:02 UTC (permalink / raw)
  To: gregkh, jslaby
  Cc: ricardo.ribalda, alan, peter, tom_tsai, peter_hong, linux-serial,
	linux-kernel, Ji-Ze Hong (Peter Hong)

Some BIOS only use _OSI("Linux") to distinguish between Linux & Windows.
Apply Level/Low to UART trigger mode if Windows, Edge/High mode otherwise.
But since 2.6.23 the mainline kernel no longer returns true for
_OSI(“Linux”).

The default IRQ0~15 trigger mode in Linux is Edge/High mode without
ACPI MADT override. It mismatches IRQ mode and makes UART malfunctional on
such motherboard.

This patch will check the current IRQ mode and apply correct mode to UART.

The following link is F81216AD spec PDF:
http://html.alldatasheet.com/html-pdf/257956/FINTEK/F81216AD/5569/
25/F81216AD.html

LDN0~3
	70h: IRQ channel & Mode register
		Bit 6~5	:
			00	: Active low level mode
			01	: Active high edge mode
		Bit 4	: Sharing Flag (0: not share/1: share)
		Bit 3~0 : IRQ channel

Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>
---
 drivers/tty/serial/8250/8250_fintek.c | 36 ++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
index 870981d..737b4b3 100644
--- a/drivers/tty/serial/8250/8250_fintek.c
+++ b/drivers/tty/serial/8250/8250_fintek.c
@@ -13,6 +13,7 @@
 #include <linux/pnp.h>
 #include <linux/kernel.h>
 #include <linux/serial_core.h>
+#include <linux/irq.h>
 #include  "8250.h"
 
 #define ADDR_PORT 0
@@ -30,6 +31,12 @@
 #define IO_ADDR2 0x60
 #define LDN 0x7
 
+#define IRQ_MODE	0x70
+#define IRQ_SHARE	BIT(4)
+#define IRQ_MODE_MASK	(BIT(6) | BIT(5))
+#define IRQ_LEVEL_LOW	0
+#define IRQ_EDGE_HIGH	BIT(5)
+
 #define RS485  0xF0
 #define RTS_INVERT BIT(5)
 #define RS485_URA BIT(4)
@@ -176,10 +183,37 @@ static int find_base_port(struct fintek_8250 *pdata, u16 io_address)
 	return -ENODEV;
 }
 
+static int fintek_8250_set_irq_mode(struct fintek_8250 *pdata, bool level_mode)
+{
+	int status;
+	u8 tmp;
+
+	status = fintek_8250_enter_key(pdata->base_port, pdata->key);
+	if (status)
+		return status;
+
+	outb(LDN, pdata->base_port + ADDR_PORT);
+	outb(pdata->index, pdata->base_port + DATA_PORT);
+
+	outb(IRQ_MODE, pdata->base_port + ADDR_PORT);
+	tmp = inb(pdata->base_port + DATA_PORT);
+
+	tmp &= ~IRQ_MODE_MASK;
+	tmp |= IRQ_SHARE;
+	if (!level_mode)
+		tmp |= IRQ_EDGE_HIGH;
+
+	outb(tmp, pdata->base_port + DATA_PORT);
+	fintek_8250_exit_key(pdata->base_port);
+	return 0;
+}
+
 int fintek_8250_probe(struct uart_8250_port *uart)
 {
 	struct fintek_8250 *pdata;
 	struct fintek_8250 probe_data;
+	struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
+	bool level_mode = irqd_is_level_type(irq_data);
 
 	if (find_base_port(&probe_data, uart->port.iobase))
 		return -ENODEV;
@@ -192,5 +226,5 @@ int fintek_8250_probe(struct uart_8250_port *uart)
 	uart->port.rs485_config = fintek_8250_rs485_config;
 	uart->port.private_data = pdata;
 
-	return 0;
+	return fintek_8250_set_irq_mode(pdata, level_mode);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_fintek: fix the mismatched IRQ mode
  2016-05-27  2:02 [PATCH] serial: 8250_fintek: fix the mismatched IRQ mode Ji-Ze Hong (Peter Hong)
@ 2016-06-27 10:25 ` Ricardo Ribalda Delgado
  2016-06-28  0:51   ` Ji-Ze Hong (Peter Hong)
  0 siblings, 1 reply; 3+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-27 10:25 UTC (permalink / raw)
  To: Ji-Ze Hong (Peter Hong)
  Cc: Greg Kroah-Hartman, jslaby, Alan Cox, Peter Hurley,
	PA20 TOM TSAI 蔡宗佑,
	Peter H, linux-serial, LKML, Ji-Ze Hong (Peter Hong)

Hi Peter,. Hi Greg

On Fri, May 27, 2016 at 4:02 AM, Ji-Ze Hong (Peter Hong)
<hpeter@gmail.com> wrote:
>  {
>         struct fintek_8250 *pdata;
>         struct fintek_8250 probe_data;
> +       struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
> +       bool level_mode = irqd_is_level_type(irq_data);

I see a potential problem with this patch:

If irq_get_irq_data fails, it will return NULL, resulting on a
segmentation fault on irqd_is_level_type:



#define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)


I believe that we need to add error checks here

>
>         if (find_base_port(&probe_data, uart->port.iobase))
>                 return -ENODEV;
> @@ -192,5 +226,5 @@ int fintek_8250_probe(struct uart_8250_port *uart)
>         uart->port.rs485_config = fintek_8250_rs485_config;
>         uart->port.private_data = pdata;
>
> -       return 0;
> +       return fintek_8250_set_irq_mode(pdata, level_mode);

Also why do not call irq_get_irq_data() and  irqd_is_level_type()
before return? There is no need to do that work if the probe
determines that it is not a fintek chip.


Greg, this is already queued for 4.7.... what shall we do here?


Regards!




-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_fintek: fix the mismatched IRQ mode
  2016-06-27 10:25 ` Ricardo Ribalda Delgado
@ 2016-06-28  0:51   ` Ji-Ze Hong (Peter Hong)
  0 siblings, 0 replies; 3+ messages in thread
From: Ji-Ze Hong (Peter Hong) @ 2016-06-28  0:51 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado
  Cc: Greg Kroah-Hartman, jslaby, Alan Cox, Peter Hurley,
	PA20 TOM TSAI 蔡宗佑,
	Peter H, linux-serial, LKML, Ji-Ze Hong (Peter Hong)

Hi Ricardo & Greg,

Ricardo Ribalda Delgado 於 2016/6/27 下午 06:25 寫道:
> Hi Peter,. Hi Greg
> On Fri, May 27, 2016 at 4:02 AM, Ji-Ze Hong (Peter Hong)
>> +       struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
>> +       bool level_mode = irqd_is_level_type(irq_data);
>
> I see a potential problem with this patch:
>
> If irq_get_irq_data fails, it will return NULL, resulting on a
> segmentation fault on irqd_is_level_type:
>
> #define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
>
>
> I believe that we need to add error checks here

I'll try to send a patch to add more checks.

>> -       return 0;
>> +       return fintek_8250_set_irq_mode(pdata, level_mode);
>
> Also why do not call irq_get_irq_data() and  irqd_is_level_type()
> before return? There is no need to do that work if the probe
> determines that it is not a fintek chip.
>

Also determine the IRQ mode when found a fintek chip.

Thanks to point out the potential issue.
-- 
With Best Regards,
Peter Hung

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-28  0:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-27  2:02 [PATCH] serial: 8250_fintek: fix the mismatched IRQ mode Ji-Ze Hong (Peter Hong)
2016-06-27 10:25 ` Ricardo Ribalda Delgado
2016-06-28  0:51   ` Ji-Ze Hong (Peter Hong)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).