Skip to contentSkip to conversation

WCH CH-382 support: help with patching

PATCH Sergej Pupykin 2 participants 3 messages Jan 22, 2014 – Oct 14, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I have wch ch382 board which is mostly similar to already supported ch353 I think. But 382 works in PCI-E slot whereas 353 in PCI.

I've written a patch and LPT looks working with parport_serial. (Actually it works even using "modprobe parport_pc io=0xe100")

But I have some problems with ttyS*.

Here are changes between CH353-2S1P and CH382-2S1P in vendor driver:

           CH353  CH382
type       16550  16750
IntrBar    3      0
IntrOffset 0x0F   0xE9
ofs1       0,0    0xC0,0xC8

As I understand last line is offset to uart I/O ports, so I put 0xC0 to pci_parport_serial_boards[].first_offset and uart_offset is 8, so /sys/class/tty/ttyS0/port is 0xE0C0 /sys/class/tty/ttyS1/port is 0xE0C8
and lspci -v reports "I/O ports at e000 [size=256]"

But I cannot find where should I put interrupt parameters IntrBar and IntrOffset. Probably this is the reason why ttyS* don't work.

Here is vendor WCH driver:
https://home.p5n.pp.ru/~sergej/files/wch-driver.tar.gz

My patch is in attachment.

drivers/parport/parport_serial.c +10 -0
diff -wbBur linux-3.12.org/drivers/parport/parport_serial.c linux-3.12/drivers/parport/parport_serial.c
@@ -63,6 +63,7 @@
 	timedia_9079b,
 	timedia_9079c,
 	wch_ch353_2s1p,
+	wch_ch382_2s1p,
 	sunix_2s1p,
 };
 
@@ -149,6 +150,7 @@
 	/* timedia_9079b */             { 1, { { 2, 3 }, } },
 	/* timedia_9079c */             { 1, { { 2, 3 }, } },
 	/* wch_ch353_2s1p*/             { 1, { { 2, -1}, } },
+	/* wch_ch382_2s1p*/             { 1, { { 2, -1}, } },
 	/* sunix_2s1p */                { 1, { { 3, -1 }, } },
 };
 
@@ -254,6 +256,7 @@
 
 	/* WCH CARDS */
 	{ 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p},
+	{ 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p},
 
 	/*
 	 * More SUNIX variations. At least one of these has part number
@@ -485,6 +488,13 @@
 		.base_baud      = 115200,
 		.uart_offset    = 8,
 	},
+	[wch_ch382_2s1p] = {
+		.flags          = FL_BASE0,
+		.num_ports      = 2,
+		.base_baud      = 115200,
+		.uart_offset    = 8,
+		.first_offset   = 0xC0,
+	},
 	[sunix_2s1p] = {
 		.flags		= FL_BASE0|FL_BASE_BARS,
 		.num_ports	= 2,
drivers/tty/serial/8250/8250_pci.c +27 -0
diff -wbBur linux-3.12.org/drivers/tty/serial/8250/8250_pci.c linux-3.12/drivers/tty/serial/8250/8250_pci.c
@@ -1521,6 +1521,22 @@
 	return pci_default_setup(priv, board, port, idx);
 }
 
+static int
+pci_wch_ch382_setup(struct serial_private *priv,
+                    const struct pciserial_board *board,
+                    struct uart_8250_port *port, int idx)
+{
+#if 0
+	unsigned int bar = FL_GET_BASE(board->flags);
+	unsigned int offset = board->first_offset;
+	offset += idx * board->uart_offset;
+	return setup_port(priv, port, bar, offset, board->reg_shift);
+#endif
+	port->port.flags |= UPF_FIXED_TYPE;
+	port->port.type = PORT_16750;
+	return pci_default_setup(priv, board, port, idx);
+}
+
 #define PCI_VENDOR_ID_SBSMODULARIO	0x124B
 #define PCI_SUBVENDOR_ID_SBSMODULARIO	0x124B
 #define PCI_DEVICE_ID_OCTPRO		0x0001
@@ -1554,10 +1570,12 @@
 #define PCI_DEVICE_ID_PLX_CRONYX_OMEGA	0xc001
 #define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d
 #define PCI_VENDOR_ID_WCH		0x4348
+#define PCIE_VENDOR_ID_WCH		0x1c00
 #define PCI_DEVICE_ID_WCH_CH352_2S	0x3253
 #define PCI_DEVICE_ID_WCH_CH353_4S	0x3453
 #define PCI_DEVICE_ID_WCH_CH353_2S1PF	0x5046
 #define PCI_DEVICE_ID_WCH_CH353_2S1P	0x7053
+#define PCIE_DEVICE_ID_WCH_CH382_2S1P	0x3250
 #define PCI_VENDOR_ID_AGESTAR		0x5372
 #define PCI_DEVICE_ID_AGESTAR_9375	0x6872
 #define PCI_VENDOR_ID_ASIX		0x9710
@@ -2182,6 +2200,14 @@
 		.subdevice	= PCI_ANY_ID,
 		.setup		= pci_wch_ch353_setup,
 	},
+	/* WCH CH382 2S1P card (16750 clone) */
+	{
+		.vendor         = PCIE_VENDOR_ID_WCH,
+		.device         = PCIE_DEVICE_ID_WCH_CH382_2S1P,
+		.subvendor      = PCI_ANY_ID,
+		.subdevice      = PCI_ANY_ID,
+		.setup          = pci_wch_ch382_setup,
+	},
 	/*
 	 * ASIX devices with FIFO bug
 	 */
@@ -3212,6 +3238,7 @@
 
 	/* multi-io cards handled by parport_serial */
 	{ PCI_DEVICE(0x4348, 0x7053), }, /* WCH CH353 2S1P */
+	{ PCI_DEVICE(0x1c00, 0x3250), }, /* WCH CH382 2S1P */
 };
 
 /*
#1 lore raw

Hi,

I am just received the similar board, but it is strange that I have different device-id, which is 3050.

Where did you get vendor driver from?

22.01.2014 15:51, Sergej Pupykin пишет:

Quoted 26 lines

Hi,

I have wch ch382 board which is mostly similar to already supported ch353 I think. But 382 works in PCI-E slot whereas 353 in PCI.

I've written a patch and LPT looks working with parport_serial. (Actually it works even using "modprobe parport_pc io=0xe100")

But I have some problems with ttyS*.

Here are changes between CH353-2S1P and CH382-2S1P in vendor driver:

           CH353  CH382
type       16550  16750
IntrBar    3      0
IntrOffset 0x0F   0xE9
ofs1       0,0    0xC0,0xC8

As I understand last line is offset to uart I/O ports, so I put 0xC0 to pci_parport_serial_boards[].first_offset and uart_offset is 8, so /sys/class/tty/ttyS0/port is 0xE0C0 /sys/class/tty/ttyS1/port is 0xE0C8
and lspci -v reports "I/O ports at e000 [size=256]"

Quoted 8 lines

But I cannot find where should I put interrupt parameters IntrBar and IntrOffset. Probably this is the reason why ttyS* don't work.

Here is vendor WCH driver:
https://home.p5n.pp.ru/~sergej/files/wch-driver.tar.gz

My patch is in attachment.

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

At Wed, 09 Jul 2014 18:47:44 +0400,

Quoted 8 lines · Matwey V. Kornilov

Hi,

I am just received the similar board, but it is strange that I have different device-id, which is 3050.

Where did you get vendor driver from?

I think driver was on CD that I got with card.

I've made patch for current git and sending it now.