Skip to contentSkip to conversation

Add Driver for SUNIX PCI(e) I/O expansion board

PATCH New Moriis Ku 1 participant 1 message Mar 30, 2021 Multifunction devices (MFD)

lore
Share & tools
lore

Moriis Ku

author
#0 lore raw

PATCH 1/1 Add Driver for SUNIX PCI(e) I/O expansion board

From: Morris <[email protected]>

The board provide UART, DIO and CAN functions.

---
 drivers/mfd/bus.c          | 1524 +++++++++++++++
 drivers/mfd/dio.c          |  529 +++++
 drivers/mfd/dio_pack.c     | 3126 +++++++++++++++++++++++++++++
 drivers/mfd/list.c         |   99 +
 drivers/mfd/mem.c          |   37 +
 drivers/mfd/sdc_define.h   |  668 +++++++
 drivers/mfd/sdc_function.h |   96 +
 drivers/mfd/sdc_include.h  |  108 +
 drivers/mfd/spi.c          |  420 ++++
 drivers/mfd/spi_pack.c     | 1506 ++++++++++++++
 drivers/mfd/uart.c         | 3796 ++++++++++++++++++++++++++++++++++++
 11 files changed, 11909 insertions(+)
 create mode 100644 drivers/mfd/bus.c
 create mode 100644 drivers/mfd/dio.c
 create mode 100644 drivers/mfd/dio_pack.c
 create mode 100644 drivers/mfd/list.c
 create mode 100644 drivers/mfd/mem.c
 create mode 100644 drivers/mfd/sdc_define.h
 create mode 100644 drivers/mfd/sdc_function.h
 create mode 100644 drivers/mfd/sdc_include.h
 create mode 100644 drivers/mfd/spi.c
 create mode 100644 drivers/mfd/spi_pack.c
 create mode 100644 drivers/mfd/uart.c
drivers/mfd/bus.c new file +1524 -0
new file mode 100644
index 000000000000..7820072e918f
@@ -0,0 +1,1524 @@
+/*
+ *	Driver for SUNIX PCI(e) expansion board
+ *	Based on drivers/tty/serial/8250/8250_pci.c
+ *	by Linus Torvalds, Theodore Ts'o.
+ *
+ *	This program is free software; you can redistribute it and/or modify
+ *	it under the terms of the GNU General Public License as published by
+ *	the Free Software Foundation; either version 2 of the License.
+ */
+
+
+#include "sdc_include.h"
+
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+static  struct pci_device_id	sunix_pci_board_id[] = 
+{
+	{0x1fd4, 0x2000, 0x1fd4, 0x0001, 0, 0, 123},
+	{0}
+};
+MODULE_DEVICE_TABLE(pci, sunix_pci_board_id);
+#else
+typedef struct
+{
+	unsigned short vendor;
+	unsigned short device;
+	unsigned short subvendor;
+	unsigned short subdevice;
+	unsigned short driver_data;
+	unsigned short part_number;
+} sunix_pciInfo;
+
+static sunix_pciInfo sunix_pci_board_id[] = 
+{
+	{0x1fd4, 0x2000, 0x1fd4, 0x0001, 123},
+	{0}
+};
+#endif
+
+
+struct sunix_sdc_board			sunix_sdc_board_table[SUNIX_SDC_BOARD_MAX];
+struct sunix_sdc_uart_channel	sunix_sdc_uart_table[SUNIX_SDC_UART_MAX + 1];
+struct sunix_sdc_dio_channel	sunix_sdc_dio_table[SUNIX_SDC_DIO_MAX];
+struct sunix_sdc_spi_channel	sunix_sdc_spi_table[SUNIX_SDC_SPI_MAX];
+
+struct kmem_cache *				sunix_sdc_dio_pack_cache;
+struct kmem_cache *				sunix_sdc_spi_pack_cache;
+
+unsigned int					sunix_sdc_board_amount;
+unsigned int					sunix_sdc_uart_amount;
+unsigned int					sunix_sdc_dio_amount;
+unsigned int					sunix_sdc_spi_amount;
+
+
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
+static irqreturn_t sunix_interrupt(int irq, void *dev_id)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+static irqreturn_t sunix_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+#else
+static void sunix_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+#endif
+{
+	struct sunix_sdc_board *sb = NULL;
+	struct sunix_sdc_uart_channel *uart_chl = NULL;
+	struct sunix_sdc_dio_channel *dio_chl = NULL;
+	struct sunix_sdc_spi_channel *spi_chl = NULL;
+	int i, j, k;
+	int status = 0;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+	int handled = IRQ_NONE;
+#endif
+	unsigned int vector[8];
+	unsigned int event_header;
+	unsigned char chl_num;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		if (dev_id == &(sunix_sdc_board_table[i]))
+		{
+			sb = dev_id;
+			break;
+		}
+	}
+
+	if (i == SUNIX_SDC_BOARD_MAX)
+		status = 1;
+
+	if (!sb)
+		status = 1;
+
+	if (sb->board_enum <= 0)
+		status = 1;
+
+	if (status != 0)
+	{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+		return handled;
+#else
+		return;
+#endif
+	}
+
+	vector[0] = mem_rx32(sb->bar0_membase, 0, 0);
+	vector[1] = mem_rx32(sb->bar0_membase, 0, 1);
+	vector[2] = mem_rx32(sb->bar0_membase, 0, 2);
+	vector[3] = mem_rx32(sb->bar0_membase, 0, 3);
+	vector[4] = mem_rx32(sb->bar0_membase, 0, 4);
+	vector[5] = mem_rx32(sb->bar0_membase, 0, 5);
+	vector[6] = mem_rx32(sb->bar0_membase, 0, 6);
+	vector[7] = mem_rx32(sb->bar0_membase, 0, 7);
+
+	for (i = 0; i < 8; i++)
+	{
+		if (vector[i] & 0xffffffff)
+		{
+			for (j = 0; j < 32; j++)
+			{
+				if (vector[i] & (0x00000001 << j))
+				{
+					chl_num = (i * 8) + j;
+
+					event_header = mem_rx32(sb->bar0_membase, 0, 8 + chl_num);
+
+					for (k = 0; k < SUNIX_SDC_UART_MAX + 1; k++)
+					{
+						uart_chl = &sunix_sdc_uart_table[k];
+
+						// uart
+						if ((uart_chl->port.iobase != 0) && 
+							(uart_chl->port.bus_number == sb->bus_number) &&
+							(uart_chl->port.dev_number == sb->dev_number) &&
+							(uart_chl->port.cib_info.num == chl_num) &&
+							(uart_chl->port.cib_info.type == 0x01))
+						{
+							//printk("SUNIX: bus_num:%d, dev_num:%d, chl_num:%d, event:x%08x, ttySDC%d has interrupt\n", uart_chl->port.bus_number, uart_chl->port.dev_number, chl_num, event_header, uart_chl->port.line);
+							status = sb->uart_isr(uart_chl);
+						}
+					}
+
+					for (k = 0; k < SUNIX_SDC_DIO_MAX; k++)
+					{
+						dio_chl = &sunix_sdc_dio_table[k];
+
+						// dio
+						if ((dio_chl->info.memsize != 0) && 
+							(dio_chl->info.bus_number == sb->bus_number) &&
+							(dio_chl->info.dev_number == sb->dev_number) &&
+							(dio_chl->info.cib_info.num == chl_num) &&
+							(dio_chl->info.cib_info.type == 0x02))
+						{
+							//printk("SUNIX: bus_num:%d, dev_num:%d, chl_num:%d, event:x%08x, SDCDIO%d has interrupt\n", dio_chl->info.bus_number, dio_chl->info.dev_number, chl_num, event_header, dio_chl->info.line);
+							status = sb->dio_isr(dio_chl, event_header);
+						}
+					}
+
+					for (k = 0; k < SUNIX_SDC_SPI_MAX; k++)
+					{
+						spi_chl = &sunix_sdc_spi_table[k];
+
+						// spi
+						if ((spi_chl->info.memsize != 0) && 
+							(spi_chl->info.bus_number == sb->bus_number) &&
+							(spi_chl->info.dev_number == sb->dev_number) &&
+							(spi_chl->info.cib_info.num == chl_num) &&
+							(spi_chl->info.cib_info.type == 0x03))
+						{
+							//printk("SUNIX: bus_num:%d, dev_num:%d, chl_num:%d, event:x%08x, SDCSPI%d has interrupt\n", spi_chl->info.bus_number, spi_chl->info.dev_number, chl_num, event_header, spi_chl->info.line);
+							status = sb->spi_isr(spi_chl, event_header);
+						}
+					}
+				}
+			}
+		}
+	}
+
+	if (status != 0)
+	{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+		return handled;
+#else
+		return;
+#endif
+	}
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+	handled = IRQ_HANDLED;
+	return handled;
+#endif
+}
+
+
+static int snx_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
+{
+	return 0;
+}
+
+
+static int snx_suspend_one(struct pci_dev *pdev, pm_message_t state)
+{
+	return  0;
+}
+
+
+static int snx_set_port_termios(struct snx_ser_state *state)
+{
+	struct tty_struct *tty = state->info->tty;
+	struct SNXTERMIOS *termios;
+	int retval = 0;
+
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
+	termios = &tty->termios;
+#else
+	termios = tty->termios;
+#endif
+
+	retval = snx_ser_startup(state, 0);
+
+	if (retval == 0)
+	{
+		snx_ser_update_termios(state);
+	}
+
+	return 0;
+}
+
+
+static int snx_resume_port_termios(struct snx_ser_info *info)
+{
+	struct snx_ser_state *state = NULL;
+	struct tty_struct *tty = info->tty ;
+
+
+	state = tty->driver_data;
+	snx_set_port_termios(state);
+
+	return 0;
+}
+
+
+static int snx_resume_port(struct sunix_sdc_uart_channel *uart_chl)
+{
+	struct snx_ser_port *port = &uart_chl->port;
+	struct snx_ser_info *info = port->info;
+
+
+	if (info)
+	{
+		snx_resume_port_termios(info);
+	}
+
+	return 0;
+}
+
+
+static int snx_resume_one(struct pci_dev *pdev)
+{
+	struct sunix_sdc_board *sb = pci_get_drvdata(pdev);
+	struct sunix_sdc_uart_channel *uart_chl = NULL;
+	int j;
+
+
+	if (sb == NULL)
+	{
+		return 0;
+	}
+
+	for (j = 0; j < sb->uart_amount; j++)
+	{
+		uart_chl = &sunix_sdc_uart_table[sb->uart_start_index + j];
+
+		if (uart_chl == NULL)
+		{
+			return 0;
+		}
+
+		if (uart_chl->port.suspended == 1)
+		{
+			snx_resume_port(uart_chl);
+		}
+	}
+
+	return 0;
+}
+
+
+static int sunix_pci_board_probe(void)
+{
+	struct sunix_sdc_board *sb;
+	struct pci_dev *pdev = NULL;
+	struct pci_dev *pdev_array[4] = {NULL, NULL, NULL, NULL};
+	int sunix_pci_board_id_cnt;
+	int tablecnt;
+	int board_amount = 0;
+	int i, j;
+	unsigned short int sub_device_id;
+	int status;
+	unsigned char data1B;
+	unsigned int data8B;
+
+
+	// clear and init some variable
+	memset(sunix_sdc_board_table, 0, SUNIX_SDC_BOARD_MAX * sizeof(struct sunix_sdc_board));
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sunix_sdc_board_table[i].board_enum = -1;
+		sunix_sdc_board_table[i].board_number = -1;
+		sunix_sdc_board_table[i].bar0_membase = NULL;
+		sunix_sdc_board_table[i].bar2_membase = NULL;
+	}
+	sunix_pci_board_id_cnt = (sizeof(sunix_pci_board_id) / sizeof(sunix_pci_board_id[0])) - 1;
+
+
+	// search 
+	pdev = NULL;
+	tablecnt = 0;
+	sub_device_id = 0;
+	status = 0;
+
+	while (tablecnt < sunix_pci_board_id_cnt)
+	{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+		pdev = pci_get_device(0x1fd4, 0x2000, pdev);
+#else
+		pdev = pci_find_device(0x1fd4, 0x2000, pdev);
+#endif
+
+		if (pdev == NULL)
+		{
+			tablecnt++;
+			continue;
+		}
+
+		if ((tablecnt > 0) && ((pdev == pdev_array[0]) || (pdev == pdev_array[1]) || (pdev == pdev_array[2]) || (pdev == pdev_array[3])))
+		{
+			continue;
+		}
+
+		pci_read_config_word(pdev, 0x2e, &sub_device_id);
+
+		if (sub_device_id == 0)
+		{
+			printk("SUNIX: Board (bus:%d device:%d), in configuration space, subdevice id isn't vaild.\n", pdev->bus->number, PCI_SLOT(pdev->devfn));
+			status = -EIO;
+			return status;
+		}
+
+		if (sub_device_id != sunix_pci_board_id[tablecnt].subdevice)
+		{
+			continue;
+		}
+
+		if (pdev == NULL)
+		{
+			printk("SUNIX: PCI device object is an NULL pointer !\n");
+			status = -EIO;
+			return status;
+		}
+		else
+		{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
+
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 3))
+			pci_disable_device(pdev);
+#endif
+			status = pci_enable_device(pdev);
+			if (status != 0)
+			{
+				printk("SUNIX: Board Enable Fail !\n");
+				status = -ENXIO;
+				return status;
+			}
+		}
+
+		if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM))
+		{
+			printk("SUNIX: Incorrect BAR0 configuration.\n");
+			status = -ENODEV;
+			return status;
+		}
+		if (!(pci_resource_flags(pdev, 1) & IORESOURCE_IO))
+		{
+			printk("SUNIX: Incorrect BAR1 configuration.\n");
+			status = -ENODEV;
+			return status;
+		}
+		if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM))
+		{
+			printk("SUNIX: Incorrect BAR2 configuration.\n");
+			status = -ENODEV;
+			return status;
+		}
+
+
+		board_amount++;
+		if (board_amount > SUNIX_SDC_BOARD_MAX)
+		{
+			printk("SUNIX: Driver support 4 boards in maximum !\n");
+			status = -ENOSPC;
+			return status;
+		}
+
+		sb = &sunix_sdc_board_table[board_amount-1];
+		pdev_array[board_amount-1] = pdev;
+
+
+		sb->pdev = pdev;
+		sb->board_enum = (int)sunix_pci_board_id[tablecnt].driver_data;
+		sb->board_number = board_amount - 1;
+		sb->bus_number = pdev->bus->number;
+		sb->dev_number = PCI_SLOT(pdev->devfn);
+		sb->irq = pdev->irq;
+
+		sb->bar0_membase = mem_get_bar_ioremap(pdev, 0);
+		sb->bar1_iobase = pci_resource_start(pdev, 1);
+		sb->bar2_membase = mem_get_bar_ioremap(pdev, 2);
+		data8B = mem_rx32(sb->bar2_membase, 0, 0);
+		sb->major_version = data8B & 0x000000ff;
+		sb->minor_version = (data8B & 0x0000ff00) >> 8;
+		sb->aval_channels = (data8B & 0x00ff0000) >> 16;
+
+		j = 0;
+		memset(sb->model_name, 0, sizeof(sb->model_name));
+		for (i = 0; i < 4; i++)
+		{
+			data8B = mem_rx32(sb->bar2_membase, 0, 2 + i);
+
+			data1B = data8B & 0x000000ff;
+			if (data1B == 0x00)
+				break;
+			sb->model_name[j++] = data1B;
+
+			data1B = (data8B & 0x0000ff00) >> 8;
+			if (data1B == 0x00)
+				break;
+			sb->model_name[j++] = data1B;
+
+			data1B = (data8B & 0x00ff0000) >> 16;
+			if (data1B == 0x00)
+				break;
+			sb->model_name[j++] = data1B;
+
+			data1B = (data8B & 0xff000000) >> 24;
+			if (data1B == 0x00)
+				break;
+			sb->model_name[j++] = data1B;
+		}
+	}
+
+
+	if (board_amount == 0)
+	{
+		printk("SUNIX: No board found !\n");
+		status = -ENXIO;
+		return status;
+	}
+	else
+	{
+		for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+		{
+			sb = &sunix_sdc_board_table[i];
+
+			if (sb->board_enum > 0)
+			{
+				printk("SUNIX: Found %s board (bus_num:%d, dev_num:%d, maj_v:%d, min_vr:%d)\n", sb->model_name, sb->bus_number, sb->dev_number, sb->major_version, sb->minor_version);
+			}
+		}
+		sunix_sdc_board_amount  = board_amount;
+    }
+
+	return status;
+}
+
+
+static int sunix_get_pci_board_conf(void)
+{
+    struct sunix_sdc_board *sb = NULL;
+    int status = 0;
+    int i, j, k, l;
+	unsigned int data8B;
+	unsigned int cib_addr;
+	unsigned int cib_addr_offset;
+	unsigned short next_ptr;
+	int uart_amount;
+	int dio_amount;
+	int spi_amount;
+	unsigned int dio_io_mask = 0;
+	unsigned int dio_io_shift_bits = 0;
+	unsigned int dio_io_direction = 0;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+
+		if (sb->board_enum > 0)
+		{
+			dio_io_shift_bits = 0;
+
+			data8B = mem_rx32(sb->bar2_membase, 0, 1);
+			next_ptr = data8B & 0x0000ffff;
+
+			uart_amount = 0;
+			dio_amount = 0;
+			spi_amount = 0;
+
+			cib_addr = 0;
+			for (j = 0; j < sb->aval_channels; j++)
+			{
+				cib_addr = next_ptr;
+				cib_addr_offset = 0;
+				data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+				sb->channel[j].num = data8B & 0x000000ff;
+				sb->channel[j].type = (data8B & 0x0000ff00) >> 8;
+				sb->channel[j].version = (data8B & 0x00ff0000) >> 16;
+				sb->channel[j].lengthInDW = (data8B & 0xff000000) >> 24;
+
+				data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+				next_ptr = data8B & 0x0000ffff;
+				sb->channel[j].capability = (data8B & 0x00ff0000) >> 16;
+				sb->channel[j].event_header_type = (data8B & 0xff000000) >> 24;
+
+				if ((sb->channel[j].capability & 0x03) == 0x03)
+				{
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].io_addr_offset = data8B & 0x00ffffff;
+					sb->channel[j].io_space_size = (data8B & 0xff000000) >> 24;
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].mem_addr_offset = data8B;
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].mem_space_size = data8B;
+				}
+				else if ((sb->channel[j].capability & 0x01) == 0x01)
+				{
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].io_addr_offset = data8B & 0x00ffffff;
+					sb->channel[j].io_space_size = (data8B & 0xff000000) >> 24;
+				}
+				else if ((sb->channel[j].capability & 0x02) == 0x02)
+				{
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].mem_addr_offset = data8B;
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].mem_space_size = data8B;
+				}
+
+				if (sb->channel[j].type == 0x00)
+				{
+					// configuration controller
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].cfg_ic_model = data8B & 0x000000ff;
+				}
+
+				if (sb->channel[j].type == 0x01)
+				{
+					uart_amount++;
+					// uart controller
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].uart_tx_fifo_size = data8B & 0x0000ffff;
+					sb->channel[j].uart_rx_fifo_size = (data8B & 0xffff0000) >> 16;
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].uart_significand_of_clock = data8B & 0x00ffffff;
+					sb->channel[j].uart_exponent_of_clock = (data8B & 0xff000000) >> 24;
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].uart_RS232_cap = data8B & 0x00000001;
+					sb->channel[j].uart_RS422_cap = (data8B & 0x00000002) >> 1;
+					sb->channel[j].uart_RS485_cap = (data8B & 0x00000004) >> 2;
+					sb->channel[j].uart_AHDC_cap = (data8B & 0x00000008) >> 3;
+					sb->channel[j].uart_CS_cap = (data8B & 0x00000010) >> 4;
+					sb->channel[j].uart_auto_RS422485_cap = (data8B & 0x00000020) >> 5;
+					sb->channel[j].uart_RS422_termination_cap = (data8B & 0x00000040) >> 6;
+					sb->channel[j].uart_RS485_termination_cap = (data8B & 0x00000080) >> 7;
+					sb->channel[j].uart_RI_5V_cap = (data8B & 0x00000100) >> 8;
+					sb->channel[j].uart_RI_12V_cap = (data8B & 0x00000200) >> 9;
+					sb->channel[j].uart_DCD_5V_cap = (data8B & 0x00000400) >> 10;
+					sb->channel[j].uart_DCD_12V_cap = (data8B & 0x00000800) >> 11;
+					// switch to rs422 if support rs422
+					if ((sb->channel[j].uart_RS232_cap == 0x00) && (sb->channel[j].uart_RS422_cap == 0x01))
+					{
+						outb(0x02, sb->bar1_iobase + sb->channel[j].io_addr_offset + 0x0e);
+					}
+				}
+
+				if (sb->channel[j].type == 0x02)
+				{
+					dio_amount++;
+					// dio controller
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].dio_number_of_banks = data8B & 0x000000ff;
+					sb->channel[j].dio_shares_same_direction_ctrl_cap = (data8B & 0x00000100) >> 8;
+					sb->channel[j].dio_writing_setting_to_flash_cap = (data8B & 0x00000200) >> 9;
+
+					for (k = 0; k < sb->channel[j].dio_number_of_banks; k++)
+					{
+						data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+						sb->channel[j].dio_bank_cap[k].number_of_io = data8B & 0x000000ff;
+						sb->channel[j].dio_bank_cap[k].support_inputs = (data8B & 0x00000100) >> 8;
+						sb->channel[j].dio_bank_cap[k].support_outputs = (data8B & 0x00000200) >> 9;
+						sb->channel[j].dio_bank_cap[k].rising_edge_trigger_cap = (data8B & 0x00000400) >> 10;
+						sb->channel[j].dio_bank_cap[k].falling_edge_trigger_cap = (data8B & 0x00000800) >> 11;
+					}
+
+					dio_io_direction = mem_rx32(sb->bar2_membase, sb->channel[j].mem_addr_offset, 12);
+					for (k = 0; k < sb->channel[j].dio_number_of_banks; k++)
+					{
+						dio_io_mask = 0;
+						for (l = 0; l < sb->channel[j].dio_bank_cap[k].number_of_io; l++)
+						{
+							dio_io_mask |= 0x00000001;
+							if (l < (sb->channel[j].dio_bank_cap[k].number_of_io - 1))
+								dio_io_mask = dio_io_mask <<1;
+						}
+
+						if (k > 0)
+						{
+							dio_io_shift_bits += sb->channel[j].dio_bank_cap[k-1].number_of_io;
+							dio_io_mask = dio_io_mask << dio_io_shift_bits;
+						}
+
+						sb->channel[j].dio_bank_cap[k].io_mask = dio_io_mask;
+						sb->channel[j].dio_bank_cap[k].io_shift_bits = dio_io_shift_bits;
+					}
+				}
+
+				if (sb->channel[j].type == 0x03)
+				{
+					spi_amount++;
+					// spi controller
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].spi_significand_of_clock = data8B & 0x00ffffff;
+					sb->channel[j].spi_exponent_of_clock = (data8B & 0xff000000) >> 24;
+					data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+					sb->channel[j].spi_number_of_device = data8B & 0x000000ff;
+
+					for (k = 0; k < sb->channel[j].spi_number_of_device; k++)
+					{
+						data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+						sb->channel[j].spi_device_cap[k].type = data8B & 0x00000001;
+						sb->channel[j].spi_device_cap[k].number_of_gpio_input = (data8B & 0x00000f00) >> 8;
+						sb->channel[j].spi_device_cap[k].number_of_gpio_output = (data8B & 0x0000f000) >> 12;
+
+						memset(sb->channel[j].spi_device_cap[k].name, 0, 32);
+						data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+						sb->channel[j].spi_device_cap[k].name[0] = data8B & 0x000000ff;
+						sb->channel[j].spi_device_cap[k].name[1] = (data8B & 0x0000ff00) >> 8;
+						sb->channel[j].spi_device_cap[k].name[2] = (data8B & 0x00ff0000) >> 16;
+						sb->channel[j].spi_device_cap[k].name[3] = (data8B & 0xff000000) >> 24;
+						data8B = mem_rx32(sb->bar2_membase, cib_addr, cib_addr_offset++);
+						sb->channel[j].spi_device_cap[k].name[4] = data8B & 0x000000ff;
+						sb->channel[j].spi_device_cap[k].name[5] = (data8B & 0x0000ff00) >> 8;
+						sb->channel[j].spi_device_cap[k].name[6] = (data8B & 0x00ff0000) >> 16;
+						sb->channel[j].spi_device_cap[k].name[7] = (data8B & 0xff000000) >> 24;
+					}
+				}
+			}
+
+			sb->uart_amount = uart_amount;
+			sunix_sdc_uart_amount = sunix_sdc_uart_amount + sb->uart_amount;
+
+			if (sunix_sdc_uart_amount > SUNIX_SDC_UART_MAX)
+			{
+				printk("SUNIX: Too much UART channel, maximum %d channels can be supported !\n", SUNIX_SDC_UART_MAX);
+				status = -EIO;
+				return status;
+			}
+
+			sb->dio_amount = dio_amount;
+			sunix_sdc_dio_amount = sunix_sdc_dio_amount + sb->dio_amount;
+
+			if (sunix_sdc_dio_amount > SUNIX_SDC_DIO_MAX)
+			{
+				printk("SUNIX: Too much DIO channel, maximum %d channels can be supported !\n", SUNIX_SDC_DIO_MAX);
+				status = -EIO;
+				return status;
+			}
+
+			sb->spi_amount = spi_amount;
+			sunix_sdc_spi_amount = sunix_sdc_spi_amount + sb->spi_amount;
+
+			if (sunix_sdc_spi_amount > SUNIX_SDC_SPI_MAX)
+			{
+				printk("SUNIX: Too much SPI channel, maximum %d channels can be supported !\n", SUNIX_SDC_SPI_MAX);
+				status = -EIO;
+				return status;
+			}
+		}
+	}
+
+
+
+
+#if (ENABLE_DEBUG_SDC_BUS == 1)
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+
+		if (sb->board_enum > 0)
+ 		{
+			printk("=================================\n");
+			printk("board_enum         : %d\n", sb->board_enum);
+			printk("board_number       : %d\n", sb->board_number);
+			printk("bus_number         : %d\n", sb->bus_number);
+			printk("dev_number         : %d\n", sb->dev_number);
+			printk("irq                : %d\n", sb->irq);
+			printk("bar0_membase       : %p\n", sb->bar0_membase);
+			printk("bar1_iobase        : x%08x\n", sb->bar1_iobase);
+			printk("bar2_membase       : %p\n", sb->bar2_membase);
+			printk("major_version      : %d\n", sb->major_version);
+			printk("minor_version      : %d\n", sb->minor_version);
+			printk("aval_channels      : %d\n", sb->aval_channels);
+			printk("model_name         : %s\n", sb->model_name);
+			printk("uart_amount        : %d\n", sb->uart_amount);
+			printk("dio_amount         : %d\n", sb->dio_amount);
+			printk("spi_amount         : %d\n", sb->spi_amount);
+			for (j = 0; j < sb->aval_channels; j++)
+			{
+				//
+				if (sb->channel[j].type == 0x00)
+				{
+					printk("------------------------------, CONFIG\n");
+					printk("num                : %d\n", sb->channel[j].num);
+					printk("type               : %d\n", sb->channel[j].type);
+					printk("version            : %d\n", sb->channel[j].version);
+					printk("lengthInDW         : %d\n", sb->channel[j].lengthInDW);
+					printk("capability         : x%02x\n", sb->channel[j].capability);
+					printk("event_header_type  : x%02d\n", sb->channel[j].event_header_type);
+					printk("mem_addr_offset    : x%08x\n", sb->channel[j].mem_addr_offset);
+					printk("mem_space_size     : %d\n", sb->channel[j].mem_space_size);
+					printk("cfg_ic_model       : x%02x\n", sb->channel[j].cfg_ic_model);
+					printk("------------------------------\n");
+				}
+				//
+				//
+				if (sb->channel[j].type == 0x01)
+				{
+					printk("------------------------------, UART\n");
+					printk("num                : %d\n", sb->channel[j].num);
+					printk("type               : %d\n", sb->channel[j].type);
+					printk("version            : %d\n", sb->channel[j].version);
+					printk("lengthInDW         : %d\n", sb->channel[j].lengthInDW);
+					printk("capability         : x%02x\n", sb->channel[j].capability);
+					printk("event_header_type  : x%02d\n", sb->channel[j].event_header_type);
+					printk("io_addr_offset     : x%08x\n", sb->channel[j].io_addr_offset);
+					printk("io_space_size      : %d\n", sb->channel[j].io_space_size);
+					printk("mem_addr_offset    : x%08x\n", sb->channel[j].mem_addr_offset);
+					printk("mem_space_size     : %d\n", sb->channel[j].mem_space_size);
+					printk("uart_tx_fifo_size  : %d\n", sb->channel[j].uart_tx_fifo_size);
+					printk("uart_rx_fifo_size  : %d\n", sb->channel[j].uart_rx_fifo_size);
+					printk("significand_clock  : %d\n", sb->channel[j].uart_significand_of_clock);
+					printk("exponent_clock     : %d\n", sb->channel[j].uart_exponent_of_clock);
+					printk("uart_RS232_cap     : %d\n", sb->channel[j].uart_RS232_cap);
+					printk("uart_RS422_cap     : %d\n", sb->channel[j].uart_RS422_cap);
+					printk("uart_RS485_cap     : %d\n", sb->channel[j].uart_RS485_cap);
+					printk("uart_AHDC_cap      : %d\n", sb->channel[j].uart_AHDC_cap);
+					printk("uart_CS_cap        : %d\n", sb->channel[j].uart_CS_cap);
+					printk("uart_auto_RS422485 : %d\n", sb->channel[j].uart_auto_RS422485_cap);
+					printk("uart_RS422_termin  : %d\n", sb->channel[j].uart_RS422_termination_cap);
+					printk("uart_RS485_termin  : %d\n", sb->channel[j].uart_RS485_termination_cap);
+					printk("uart_RI_5V_cap     : %d\n", sb->channel[j].uart_RI_5V_cap);
+					printk("uart_RI_12V_cap    : %d\n", sb->channel[j].uart_RI_12V_cap);
+					printk("uart_DCD_5V_cap    : %d\n", sb->channel[j].uart_DCD_5V_cap);
+					printk("uart_DCD_12V_cap   : %d\n", sb->channel[j].uart_DCD_12V_cap);
+					printk("------------------------------\n");
+				}
+				//
+				//
+				if (sb->channel[j].type == 0x02)
+				{
+					printk("------------------------------, DIO\n");
+					printk("num                : %d\n", sb->channel[j].num);
+					printk("type               : %d\n", sb->channel[j].type);
+					printk("version            : %d\n", sb->channel[j].version);
+					printk("lengthInDW         : %d\n", sb->channel[j].lengthInDW);
+					printk("capability         : x%02x\n", sb->channel[j].capability);
+					printk("event_header_type  : x%02d\n", sb->channel[j].event_header_type);
+					printk("mem_addr_offset    : x%08x\n", sb->channel[j].mem_addr_offset);
+					printk("mem_space_size     : %d\n", sb->channel[j].mem_space_size);
+					printk("dio_number_of_banks: %d\n", sb->channel[j].dio_number_of_banks);
+					printk("shares_same_direct : %d\n", sb->channel[j].dio_shares_same_direction_ctrl_cap);
+					printk("writing_setting    : %d\n", sb->channel[j].dio_writing_setting_to_flash_cap);
+					for (k = 0; k < sb->channel[j].dio_number_of_banks; k++)
+					{
+						printk("++++++++++++++++++++++++++++\n");
+						printk("number_of_io       : %d\n", sb->channel[j].dio_bank_cap[k].number_of_io);
+						printk("support_inputs     : %d\n", sb->channel[j].dio_bank_cap[k].support_inputs);
+						printk("support_outputs    : %d\n", sb->channel[j].dio_bank_cap[k].support_outputs);
+						printk("rising_trigger     : %d\n", sb->channel[j].dio_bank_cap[k].rising_edge_trigger_cap);
+						printk("falling_trigger    : %d\n", sb->channel[j].dio_bank_cap[k].falling_edge_trigger_cap);
+						printk("++++++++++++++++++++++++++++\n");
+					}
+					printk("------------------------------\n");
+				}
+				//
+				//
+				if (sb->channel[j].type == 0x03)
+				{
+					printk("------------------------------, SPI\n");
+					printk("num                : %d\n", sb->channel[j].num);
+					printk("type               : %d\n", sb->channel[j].type);
+					printk("version            : %d\n", sb->channel[j].version);
+					printk("lengthInDW         : %d\n", sb->channel[j].lengthInDW);
+					printk("capability         : x%02x\n", sb->channel[j].capability);
+					printk("event_header_type  : x%02d\n", sb->channel[j].event_header_type);
+					printk("io_addr_offset     : x%08x\n", sb->channel[j].io_addr_offset);
+					printk("io_space_size      : %d\n", sb->channel[j].io_space_size);
+					printk("mem_addr_offset    : x%08x\n", sb->channel[j].mem_addr_offset);
+					printk("mem_space_size     : %d\n", sb->channel[j].mem_space_size);
+					printk("significand_clock  : %d\n", sb->channel[j].spi_significand_of_clock);
+					printk("exponent_clock     : %d\n", sb->channel[j].spi_exponent_of_clock);
+					printk("spi_number_device  : %d\n", sb->channel[j].spi_number_of_device);
+					for (k = 0; k < sb->channel[j].spi_number_of_device; k++)
+					{
+						printk("++++++++++++++++++++++++++++\n");
+						printk("type               : %d\n", sb->channel[j].spi_device_cap[k].type);
+						printk("number_gpio_input  : %d\n", sb->channel[j].spi_device_cap[k].number_of_gpio_input);
+						printk("number_gpio_output : %d\n", sb->channel[j].spi_device_cap[k].number_of_gpio_output);
+						printk("name               : %s\n", sb->channel[j].spi_device_cap[k].name);
+						printk("++++++++++++++++++++++++++++\n");
+					}
+					printk("------------------------------\n");
+				}
+				//
+			}
+			printk("=================================\n");
+		}
+	}
+#endif
+	return status;
+}
+
+
+static int sunix_assign_resource(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	struct sunix_sdc_uart_channel *uart_chl = NULL;
+	struct sunix_sdc_dio_channel *dio_chl = NULL;
+	struct sunix_sdc_spi_channel *spi_chl = NULL;
+	int status = 0;
+	int i;
+	int j;
+	int uart_index = 0;
+	int dio_index = 0;
+	int spi_index = 0;
+
+
+	memset(sunix_sdc_uart_table, 0, (SUNIX_SDC_UART_MAX + 1) * sizeof(struct sunix_sdc_uart_channel));
+	memset(sunix_sdc_dio_table, 0, SUNIX_SDC_DIO_MAX * sizeof(struct sunix_sdc_dio_channel));
+	memset(sunix_sdc_spi_table, 0, SUNIX_SDC_SPI_MAX * sizeof(struct sunix_sdc_spi_channel));
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+
+		if (sb->board_enum > 0)
+		{
+			if (sb->uart_amount > 0)
+			{
+				sb->uart_start_index = uart_index;
+
+				for (j = 0; j < sb->aval_channels; j++)
+				{
+					if (sb->channel[j].type == 0x01)
+					{
+						uart_chl = &sunix_sdc_uart_table[uart_index];
+
+						uart_chl->port.iobase = sb->bar1_iobase + sb->channel[j].io_addr_offset;
+						uart_chl->port.iosize = sb->channel[j].io_space_size;
+						memcpy(&uart_chl->port.cib_info, &sb->channel[j], sizeof(struct sdc_cib));
+						memcpy(uart_chl->port.model_name, sb->model_name, sizeof(sb->model_name));
+
+						uart_index++;
+					}
+				}
+			}
+
+			if (sb->dio_amount > 0)
+			{
+				sb->dio_start_index = dio_index;
+
+				for (j = 0; j < sb->aval_channels; j++)
+				{
+					if (sb->channel[j].type == 0x02)
+					{
+						dio_chl = &sunix_sdc_dio_table[dio_index];
+
+						dio_chl->info.phy2_base_start = pci_resource_start(sb->pdev, 2);
+						dio_chl->info.membase = sb->bar2_membase;
+						dio_chl->info.memoffset = sb->channel[j].mem_addr_offset;
+						dio_chl->info.memsize = sb->channel[j].mem_space_size;
+						memcpy(&dio_chl->info.cib_info, &sb->channel[j], sizeof(struct sdc_cib));
+						memcpy(dio_chl->info.model_name, sb->model_name, sizeof(sb->model_name));
+
+						dio_index++;
+					}
+				}
+			}
+
+			if (sb->spi_amount > 0)
+			{
+				sb->spi_start_index = spi_index;
+
+				for (j = 0; j < sb->aval_channels; j++)
+				{
+					if (sb->channel[j].type == 0x03)
+					{
+						spi_chl = &sunix_sdc_spi_table[spi_index];
+
+						spi_chl->info.phy2_base_start = pci_resource_start(sb->pdev, 2);
+						spi_chl->info.membase = sb->bar2_membase;
+						spi_chl->info.memoffset = sb->channel[j].mem_addr_offset;
+						spi_chl->info.memsize = sb->channel[j].mem_space_size;
+						memcpy(&spi_chl->info.cib_info, &sb->channel[j], sizeof(struct sdc_cib));
+						memcpy(spi_chl->info.model_name, sb->model_name, sizeof(sb->model_name));
+
+						spi_index++;
+					}
+				}
+			}
+		}
+	}
+
+	return status;
+}
+
+
+static int sunix_uart_channel_table_init(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	struct sunix_sdc_uart_channel *uart_chl = NULL;
+	int status = 0;
+	int i;
+	int j;
+	int n;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+
+		if (sb == NULL)
+		{
+			status = -ENXIO;
+			printk("SUNIX: Board table pointer error !\n");
+			return status;
+		}
+
+		if ((sb->board_enum > 0) && (sb->uart_amount > 0))
+		{
+			n = sb->uart_start_index;
+
+			uart_chl = &sunix_sdc_uart_table[n];
+
+			if (uart_chl == NULL)
+			{
+				status = -ENXIO;
+				printk("SUNIX: UART port table pointer error !\n");
+				return status;
+			}
+
+			for (j = 0; j < sb->uart_amount; j++, n++, uart_chl++)
+			{
+				uart_chl->port.board_enum	= sb->board_enum;
+				uart_chl->port.bus_number	= sb->bus_number;
+				uart_chl->port.dev_number	= sb->dev_number;
+				uart_chl->port.baud_base = 921600;
+
+				uart_chl->port.irq = sb->irq;
+				uart_chl->port.line = n;
+				uart_chl->port.uartclk = uart_chl->port.baud_base * 16;
+				uart_chl->port.iotype = SNX_UPIO_PORT;
+				uart_chl->port.flags = ASYNC_SHARE_IRQ;
+				uart_chl->port.ldisc_stop_rx = 0;
+
+				spin_lock_init(&uart_chl->port.lock);
+
+				uart_chl->port.type = PORT_SER_16750;
+				uart_chl->port.fifosize = uart_chl->port.cib_info.uart_rx_fifo_size - 8;
+				uart_chl->port.rx_trigger = uart_chl->port.cib_info.uart_rx_fifo_size / 2;
+
+				uart_chl->port.setserial_flag = SNX_SER_BAUD_NOTSETSER;
+			}
+
+			sb->uart_isr = sunix_ser_interrupt;
+		}
+		else
+		{
+			sb->uart_isr = NULL;
+		}
+	}
+
+    return status;
+}
+
+
+static int sunix_dio_channel_table_init(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	struct sunix_sdc_dio_channel *dio_chl = NULL;
+	int status = 0;
+	int i;
+	int j;
+	int n;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+		if ((sb->board_enum > 0) && (sb->dio_amount > 0))
+		{
+			n = sb->dio_start_index;
+
+			dio_chl = &sunix_sdc_dio_table[n];
+			for (j = 0; j < sb->dio_amount; j++, n++, dio_chl++)
+			{
+				dio_chl->info.bus_number	= sb->bus_number;
+				dio_chl->info.dev_number	= sb->dev_number;
+				dio_chl->info.irq = sb->irq;
+				dio_chl->info.line = n;
+
+				spin_lock_init(&dio_chl->packLock);
+				SxxListInit(&dio_chl->packList);
+				init_waitqueue_head(&dio_chl->readWQ);
+				sema_init(&dio_chl->sem, 1);
+
+				dio_chl->isOpened = false;
+
+				dio_chl->incomeBuff = NULL;
+				dio_chl->outcomeBuff = NULL;
+				dio_chl->translateBuff = NULL;
+
+				do
+				{
+					dio_chl->incomeBuff = (unsigned char *)kmalloc(SUNIX_SDC_DIO_BUFF, GFP_KERNEL);
+					if (dio_chl->incomeBuff == NULL)
+					{
+						status = -ENOMEM;
+						break;
+					}
+					memset(dio_chl->incomeBuff, 0, SUNIX_SDC_DIO_BUFF);
+
+					dio_chl->outcomeBuff = (unsigned char *)kmalloc(SUNIX_SDC_DIO_BUFF, GFP_KERNEL);
+					if (dio_chl->outcomeBuff == NULL)
+					{
+						status = -ENOMEM;
+						break;
+					}
+					memset(dio_chl->outcomeBuff, 0, SUNIX_SDC_DIO_BUFF);
+
+					dio_chl->translateBuff = (unsigned char *)kmalloc(SUNIX_SDC_DIO_BUFF, GFP_KERNEL);
+					if (dio_chl->translateBuff == NULL)
+					{
+						status = -ENOMEM;
+						break;
+					}
+					memset(dio_chl->translateBuff, 0, SUNIX_SDC_DIO_BUFF);
+
+				} while (false);
+
+				if (status != 0)
+				{
+					if (dio_chl->incomeBuff != NULL)
+					{
+						kfree(dio_chl->incomeBuff);
+						dio_chl->incomeBuff = NULL;
+					}
+
+					if (dio_chl->outcomeBuff != NULL)
+					{
+						kfree(dio_chl->outcomeBuff);
+						dio_chl->outcomeBuff = NULL;
+					}
+
+					if (dio_chl->translateBuff != NULL)
+					{
+						kfree(dio_chl->translateBuff);
+						dio_chl->translateBuff = NULL;
+					}
+					break;
+				}
+			}
+
+			sb->dio_isr = sunix_dio_interrupt;
+		}
+		else
+		{
+			sb->dio_isr = NULL;
+		}
+
+		if (status != 0)
+		{
+			break;
+		}
+	}
+
+    return status;
+}
+
+
+static void sunix_dio_channel_table_deinit(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	struct sunix_sdc_dio_channel *dio_chl = NULL;
+	int i;
+	int j;
+	int n;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+		if ((sb->board_enum > 0) && (sb->dio_amount > 0))
+		{
+			n = sb->dio_start_index;
+
+			dio_chl = &sunix_sdc_dio_table[n];
+			for (j = 0; j < sb->dio_amount; j++, n++, dio_chl++)
+			{
+				if (dio_chl->incomeBuff != NULL)
+				{
+					kfree(dio_chl->incomeBuff);
+					dio_chl->incomeBuff = NULL;
+				}
+
+				if (dio_chl->outcomeBuff != NULL)
+				{
+					kfree(dio_chl->outcomeBuff);
+					dio_chl->outcomeBuff = NULL;
+				}
+
+				if (dio_chl->translateBuff != NULL)
+				{
+					kfree(dio_chl->translateBuff);
+					dio_chl->translateBuff = NULL;
+				}
+			}
+		}
+	}
+}
+
+
+static int sunix_spi_channel_table_init(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	struct sunix_sdc_spi_channel *spi_chl = NULL;
+	int status = 0;
+	int i;
+	int j;
+	int n;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+		if ((sb->board_enum > 0) && (sb->spi_amount > 0))
+		{
+			n = sb->spi_start_index;
+
+			spi_chl = &sunix_sdc_spi_table[n];
+			for (j = 0; j < sb->spi_amount; j++, n++, spi_chl++)
+			{
+				spi_chl->info.bus_number	= sb->bus_number;
+				spi_chl->info.dev_number	= sb->dev_number;
+				spi_chl->info.irq = sb->irq;
+				spi_chl->info.line = n;
+
+				spin_lock_init(&spi_chl->packLock);
+				SxxListInit(&spi_chl->packList);
+				init_waitqueue_head(&spi_chl->readWQ);
+				sema_init(&spi_chl->sem, 1);
+
+				spi_chl->isOpened = false;
+
+				spi_chl->incomeBuff = NULL;
+				spi_chl->outcomeBuff = NULL;
+				spi_chl->translateBuff = NULL;
+
+				do
+				{
+					spi_chl->incomeBuff = (unsigned char *)kmalloc(SUNIX_SDC_SPI_BUFF, GFP_KERNEL);
+					if (spi_chl->incomeBuff == NULL)
+					{
+						status = -ENOMEM;
+						break;
+					}
+					memset(spi_chl->incomeBuff, 0, SUNIX_SDC_SPI_BUFF);
+
+					spi_chl->outcomeBuff = (unsigned char *)kmalloc(SUNIX_SDC_SPI_BUFF, GFP_KERNEL);
+					if (spi_chl->outcomeBuff == NULL)
+					{
+						status = -ENOMEM;
+						break;
+					}
+					memset(spi_chl->outcomeBuff, 0, SUNIX_SDC_SPI_BUFF);
+
+					spi_chl->translateBuff = (unsigned char *)kmalloc(SUNIX_SDC_SPI_BUFF, GFP_KERNEL);
+					if (spi_chl->translateBuff == NULL)
+					{
+						status = -ENOMEM;
+						break;
+					}
+					memset(spi_chl->translateBuff, 0, SUNIX_SDC_SPI_BUFF);
+
+				} while (false);
+
+				if (status != 0)
+				{
+					if (spi_chl->incomeBuff != NULL)
+					{
+						kfree(spi_chl->incomeBuff);
+						spi_chl->incomeBuff = NULL;
+					}
+
+					if (spi_chl->outcomeBuff != NULL)
+					{
+						kfree(spi_chl->outcomeBuff);
+						spi_chl->outcomeBuff = NULL;
+					}
+
+					if (spi_chl->translateBuff != NULL)
+					{
+						kfree(spi_chl->translateBuff);
+						spi_chl->translateBuff = NULL;
+					}
+					break;
+				}
+			}
+
+			sb->spi_isr = sunix_spi_interrupt;
+		}
+		else
+		{
+			sb->spi_isr = NULL;
+		}
+
+		if (status != 0)
+		{
+			break;
+		}
+	}
+
+    return status;
+}
+
+
+static void sunix_spi_channel_table_deinit(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	struct sunix_sdc_spi_channel *spi_chl = NULL;
+	int i;
+	int j;
+	int n;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+		if ((sb->board_enum > 0) && (sb->spi_amount > 0))
+		{
+			n = sb->spi_start_index;
+
+			spi_chl = &sunix_sdc_spi_table[n];
+			for (j = 0; j < sb->spi_amount; j++, n++, spi_chl++)
+			{
+				if (spi_chl->incomeBuff != NULL)
+				{
+					kfree(spi_chl->incomeBuff);
+					spi_chl->incomeBuff = NULL;
+				}
+
+				if (spi_chl->outcomeBuff != NULL)
+				{
+					kfree(spi_chl->outcomeBuff);
+					spi_chl->outcomeBuff = NULL;
+				}
+
+				if (spi_chl->translateBuff != NULL)
+				{
+					kfree(spi_chl->translateBuff);
+					spi_chl->translateBuff = NULL;
+				}
+			}
+		}
+	}
+}
+
+
+int sunix_register_irq(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	int status = 0;
+	int i;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+
+		if (sb == NULL)
+		{
+			status = -ENXIO;
+			printk("SUNIX: Board table pointer error !\n");
+			return status;
+		}
+
+		if (sb->board_enum > 0)
+		{
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
+			status = request_irq(sb->irq, sunix_interrupt, IRQF_SHARED, "sunix_sdc", sb);
+#else
+			status = request_irq(sb->irq, sunix_interrupt, SA_SHIRQ, "sunix_sdc", sb);
+#endif
+			if (status)
+			{
+				printk("SUNIX: %s board (bus_num:%d dev_num:%d), request\n", sb->model_name, sb->bus_number, sb->dev_number);
+				printk("       IRQ %d fail, IRQ %d may be conflit with another device.\n", sb->irq, sb->irq);
+				return status;
+			}
+		}
+	}
+
+	return status;
+}
+
+
+void sunix_release_irq(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	int i;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+
+		if (sb->board_enum > 0)
+		{
+			free_irq(sb->irq, sb);
+		}
+	}
+}
+
+
+void sunix_release_iomap(void)
+{
+	struct sunix_sdc_board *sb = NULL;
+	int i;
+
+
+	for (i = 0; i < SUNIX_SDC_BOARD_MAX; i++)
+	{
+		sb = &sunix_sdc_board_table[i];
+
+		if (sb->board_enum > 0)
+		{
+			if (sb->bar0_membase != NULL)
+			{
+				iounmap(sb->bar0_membase);
+				sb->bar0_membase = NULL;
+			}
+
+			if (sb->bar2_membase != NULL)
+			{
+				iounmap(sb->bar2_membase);
+				sb->bar2_membase = NULL;
+			}
+		}
+	}
+}
+
+
+static struct pci_driver snx_pci_driver =
+{
+	.name			= "sunix_sdc",
+	.probe			= snx_pci_probe_one,
+	.suspend		= snx_suspend_one,
+	.resume			= snx_resume_one,
+	.id_table		= sunix_pci_board_id,
+};
+
+
+static int __init sunix_sdc_init(void)
+{
+	int status = 0;
+
+
+	sunix_sdc_board_amount = 0;
+	sunix_sdc_uart_amount = 0;
+	sunix_sdc_dio_amount = 0;
+	sunix_sdc_spi_amount = 0;
+
+
+	sunix_sdc_dio_pack_cache = kmem_cache_create("sunix_sdc_dio", sizeof(DIO_PACKAGE), 0, SLAB_HWCACHE_ALIGN, NULL);
+	if (sunix_sdc_dio_pack_cache == NULL)
+		goto step1_fail;
+
+	sunix_sdc_spi_pack_cache = kmem_cache_create("sunix_sdc_spi", sizeof(DIO_PACKAGE), 0, SLAB_HWCACHE_ALIGN, NULL);
+	if (sunix_sdc_spi_pack_cache == NULL)
+		goto step2_fail;
+
+	status = pci_register_driver(&snx_pci_driver);
+	if (status != 0)
+		goto step3_fail;
+
+	status = sunix_pci_board_probe();
+	if (status != 0)	
+		goto step4_fail;
+
+	status = sunix_get_pci_board_conf();
+	if (status != 0)
+		goto step5_fail;
+
+	status = sunix_assign_resource();
+	if (status != 0)
+		goto step5_fail;
+
+	status = sunix_uart_channel_table_init();
+	if (status != 0)
+		goto step5_fail;
+
+	status = sunix_dio_channel_table_init();
+	if (status != 0)
+		goto step5_fail;
+
+	status = sunix_spi_channel_table_init();
+	if (status != 0)
+		goto step6_fail;
+
+	status = sunix_register_irq();
+	if (status != 0)
+		goto step7_fail;
+
+	status = sunix_ser_register_driver();
+	if (status != 0)
+		goto step8_fail;
+
+	status = sunix_ser_register_ports();
+	if (status != 0)
+		goto step9_fail;
+
+	status = sunix_dio_register_channel();
+	if (status != 0)
+		goto step10_fail;
+
+	status = sunix_spi_register_channel();
+	if (status != 0)
+		goto step11_fail;
+
+
+	return status;
+
+
+step11_fail:
+	sunix_dio_unregister_channel();
+
+step10_fail:
+	sunix_ser_unregister_ports();
+
+step9_fail:
+	sunix_ser_unregister_driver();
+
+step8_fail:
+	sunix_release_irq();
+
+step7_fail:
+	sunix_spi_channel_table_deinit();
+
+step6_fail:
+	sunix_dio_channel_table_deinit();
+
+step5_fail:
+	sunix_release_iomap();
+
+step4_fail:
+	pci_unregister_driver(&snx_pci_driver);
+
+step3_fail:
+	kmem_cache_destroy(sunix_sdc_spi_pack_cache);
+
+step2_fail:
+	kmem_cache_destroy(sunix_sdc_dio_pack_cache);
+
+step1_fail:
+
+	return status;
+}
+
+
+static void __exit sunix_sdc_exit(void)
+{
+	sunix_spi_unregister_channel();
+
+	sunix_dio_unregister_channel();
+
+	sunix_ser_unregister_ports();
+
+	sunix_ser_unregister_driver();
+
+	sunix_release_irq();
+
+	sunix_spi_channel_table_deinit();
+
+	sunix_dio_channel_table_deinit();
+
+	sunix_release_iomap();
+
+	pci_unregister_driver(&snx_pci_driver);
+
+	kmem_cache_destroy(sunix_sdc_spi_pack_cache);
+
+	kmem_cache_destroy(sunix_sdc_dio_pack_cache);
+}
+
+
+module_init(sunix_sdc_init);
+module_exit(sunix_sdc_exit);
+
+
+MODULE_AUTHOR("SUNIX Co., Ltd.<[email protected]>");
+MODULE_DESCRIPTION("SUNIX PCI(e) expansion board bus driver");
+MODULE_LICENSE("GPL");
+
+
drivers/mfd/dio.c new file +529 -0

529 lines not on this page · raw message

drivers/mfd/dio_pack.c new file +3126 -0

947 lines not on this page · raw message

drivers/mfd/list.c new file +99 -0

99 lines not on this page · raw message

drivers/mfd/mem.c new file +37 -0
new file mode 100644
index 000000000000..1158439d0aef

Lines of this file are not shown. View the raw message.

drivers/mfd/sdc_define.h new file +668 -0

668 lines not on this page · raw message

drivers/mfd/sdc_function.h new file +96 -0

96 lines not on this page · raw message

drivers/mfd/sdc_include.h new file +108 -0

108 lines not on this page · raw message

drivers/mfd/spi.c new file +420 -0

420 lines not on this page · raw message

drivers/mfd/spi_pack.c new file +1506 -0

1,506 lines not on this page · raw message

drivers/mfd/uart.c new file +3796 -0

3,796 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.20.1

Part of the diff is not shown here. View the raw message.