Add support for SUNIX Multi-I/O board
PATCH 2/4 Add support for SUNIX Multi-I/O board
Driver for SUNIX Multi-I/O card.
Based on driver/char/serial.c by Linus Torvalds, Theodore Ts'o.
SUNIX serial card designed with SUNIX UART controller and compatible with 16C950 UART specification.
--- mfd/sunix/snx_main.c | 1671 +++++++++++++++++++ mfd/sunix/snx_serial.c | 3513 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 5184 insertions(+) create mode 100644 mfd/sunix/snx_main.c create mode 100644 mfd/sunix/snx_serial.c
mfd/sunix/snx_main.c new file +1671 -0
@@ -0,0 +1,1671 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "snx_common.h" +#include "driver_extd.h" + +#define SNX_DRIVER_AUTHOR "SUNIX Co., Ltd.<[email protected]>" +#define SNX_DRIVER_DESC "SUNIX Multi-I/O Board Driver Module" + +MODULE_AUTHOR (SNX_DRIVER_AUTHOR ); +MODULE_DESCRIPTION (SNX_DRIVER_DESC ); +MODULE_LICENSE ("GPL" ); + +static const pci_board snx_pci_board_conf[] = { + { +VENID_GOLDEN ,DEVID_G_SERIAL ,SUBVENID_GOLDEN , +SUBDEVID_TEST ,0 ,0 ,0 ,0x00 ,"none" , +BOARDFLAG_NONE ,PART_NUMBER_NONE , +CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'n' ,-1 ,0 ,0 ,-1 ,0 ,0 ,0x0000 ,SUNNONE_HWID }, + }, + }, + +// mode P1002 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1002 ,2 ,0 ,1 ,0x00 ,"1002" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + }, + }, + +// mode P1004 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1004 ,4 ,0 ,1 ,0x00 ,"1004" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUNMATX_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUNMATX_HWID }, + }, + }, + +// mode P1008 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1008 ,8 ,0 ,1 ,0x00 ,"1008" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUNMATX_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUNMATX_HWID }, + {'s' ,0 ,32 ,8 ,-1 ,0 ,0 ,0x0010 ,SUNMATX_HWID }, + {'s' ,0 ,40 ,8 ,-1 ,0 ,0 ,0x0020 ,SUNMATX_HWID }, + {'s' ,0 ,48 ,8 ,-1 ,0 ,0 ,0x0040 ,SUNMATX_HWID }, + {'s' ,0 ,56 ,8 ,-1 ,0 ,0 ,0x0080 ,SUNMATX_HWID }, + }, + }, + +// mode P1016 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1016 ,16 ,0 ,1 ,0x00 ,"1016" , +BOARDFLAG_NONE |BOARDFLAG_16PORTS , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY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ATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + }, + }, + +// mode P2004 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P2004 ,4 ,0 ,1 ,0x00 ,"2004" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUNMATX_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUNMATX_HWID }, + }, + }, + +// mode P2008 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P2008 ,8 ,0 ,1 ,0x00 ,"2008" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUNMATX_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUNMATX_HWID }, + {'s' ,0 ,32 ,8 ,-1 ,0 ,0 ,0x0010 ,SUNMATX_HWID }, + {'s' ,0 ,40 ,8 ,-1 ,0 ,0 ,0x0020 ,SUNMATX_HWID }, + {'s' ,0 ,48 ,8 ,-1 ,0 ,0 ,0x0040 ,SUNMATX_HWID }, + {'s' ,0 ,56 ,8 ,-1 ,0 ,0 ,0x0080 ,SUNMATX_HWID }, + }, + }, + +// mode P3002 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P3002 ,2 ,0 ,1 ,0x00 ,"3002" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + }, + }, + +// mode P3004 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P3004 ,4 ,0 ,1 ,0x00 ,"3004" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUNMATX_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUNMATX_HWID }, + }, + }, + +// mode P3008 + { +VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P3008 ,8 ,0 ,1 ,0x00 ,"3008" ,BOARDFLAG_NONE , +PART_NUMBER_NONE ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUNMATX_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUNMATX_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUNMATX_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUNMATX_HWID }, + {'s' ,0 ,32 ,8 ,-1 ,0 ,0 ,0x0010 ,SUNMATX_HWID }, + {'s' ,0 ,40 ,8 ,-1 ,0 ,0 ,0x0020 ,SUNMATX_HWID }, + {'s' ,0 ,48 ,8 ,-1 ,0 ,0 ,0x0040 ,SUNMATX_HWID }, + {'s' ,0 ,56 ,8 ,-1 ,0 ,0 ,0x0080 ,SUNMATX_HWID }, + }, + }, + + +// mode 5027A + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5027A ,1 ,0 ,3 ,0x00 ,"5027" ,BOARDFLAG_NONE , +0x01 ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + }, + }, + +// mode 5037A + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5037A ,2 ,0 ,3 ,0x00 ,"5037" ,BOARDFLAG_NONE , +0x02 ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + }, + }, + +// mode 5056A + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5056A ,4 ,0 ,3 ,0x00 ,"5056" ,BOARDFLAG_NONE , +0x04 ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + }, + }, + +// mode 5066A + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5066A ,8 ,0 ,3 ,0x00 ,"5066" , +BOARDFLAG_NONE ,0x08 ,CARD_TYPE_UART_ONLY ,GPIO_NON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,72 ,8 ,-1 ,0 ,0 ,0x0020 ,SUN1999_HWID }, + {'s' ,1 ,80 ,8 ,-1 ,0 ,0 ,0x0040 ,SUN1999_HWID }, + {'s' ,1 ,88 ,8 ,-1 ,0 ,0 ,0x0080 ,SUN1999_HWID }, + {'s' ,1 ,128 ,8 ,-1 ,0 ,0 ,0x0100 ,SUN1999_HWID }, + {'s' ,1 ,136 ,8 ,-1 ,0 ,0 ,0x0200 ,SUN1999_HWID }, + {'s' ,1 ,144 ,8 ,-1 ,0 ,0 ,0x0400 ,SUN1999_HWID }, + {'s' ,1 ,152 ,8 ,-1 ,0 ,0 ,0x0800 ,SUN1999_HWID }, + }, + }, + +// mode 5069A 5069H + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5069A ,1 ,1 ,3 ,0x00 ,"5069" ,BOARDFLAG_NONE , +0x01 ,0x00 ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'p' ,1 ,0 ,8 ,2 ,0 ,0 ,0x0000 ,SUN1999_HWID }, + }, + }, + + +// mode 5079A + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5079A ,2 ,1 ,3 ,0x00 ,"5079" ,BOARDFLAG_NONE , +0x02 ,0x00 ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'p' ,1 ,0 ,8 ,2 ,0 ,0 ,0x0000 ,SUN1999_HWID }, + }, + }, + +// mode 5099A + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5099A ,4 ,1 ,3 ,0x00 ,"5099" ,BOARDFLAG_NONE , +0x04 ,0x00 ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + {'p' ,1 ,0 ,8 ,2 ,0 ,0 ,0x0000 ,SUN1999_HWID }, + }, + }, + +// mode 5008A + { +VENID_SUN1999 ,DEVID_S_PARALL ,SUBVENID_SUN1999 , +SUBDEVID_5008A ,0 ,1 ,0 ,0x00 ,"5008" ,BOARDFLAG_NONE , +0x00 ,0x00 ,GPIO_NONE , + { + {'p' ,1 ,0 ,8 ,2 ,0 ,0 ,0x0000 ,SUN1999_HWID }, + }, + }, + +// mode P2102 + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 ,SUBDEVID_P2102 , +2 ,0 ,3 ,0x00 ,"P2102" ,BOARDFLAG_NONE ,0x42 , +CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + }, + }, + +// mode P2104 + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_P2104 ,4 ,0 ,3 ,0x00 ,"P2104" ,BOARDFLAG_NONE , +0x44 ,CARD_TYPE_UART_ONLY ,GPIO_NONE , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + }, + }, + +// mode P2108 + { +VENID_SUN1999 ,DE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999_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + {'s' ,1 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,1 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'s' ,1 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,1 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + }, + }, + +// CDK1037 + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_CASH_2S ,2 ,0 ,3 ,0x00 ,"CDK1037" , +BOARDFLAG_NONE ,0x02 ,CARD_TYPE_UART_GINTR ,INTR_GPIO_6PORT , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + }, + }, + +// CDK1056 + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_CASH_4S ,4 ,0 ,3 ,0x00 ,"CDK1056" ,BOARDFLAG_NONE , +0x04 ,CARD_TYPE_UART_GINTR ,INTR_GPIO_6PORT , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + }, + }, + +// mode DIO-0802 + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_DIO0802 ,2 ,0 ,3 ,0x00 ,"DIO0802" ,BOARDFLAG_NONE , +0x02 ,CARD_TYPE_UART_GEXTR ,EXTR_GPIO_8PORT , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + }, + }, + +// mode DIO-1604 + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_DIO1604 ,4 ,0 ,3 ,0x00 ,"DIO1604" , +BOARDFLAG_NONE ,0x04 ,CARD_TYPE_UART_GEXTR ,EXTR_GPIO_16PORT , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + }, + }, + +// mode DIO-3204 + { +VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_DIO3204 ,4 ,0 ,3 ,0x00 ,"DIO3204" ,BOARDFLAG_NONE , +0x04 ,CARD_TYPE_UART_GEXTR ,EXTR_GPIO_32PORT , + { + {'s' ,0 ,0 ,8 ,-1 ,0 ,0 ,0x0001 ,SUN1999_HWID }, + {'s' ,0 ,8 ,8 ,-1 ,0 ,0 ,0x0002 ,SUN1999_HWID }, + {'s' ,0 ,16 ,8 ,-1 ,0 ,0 ,0x0004 ,SUN1999_HWID }, + {'s' ,0 ,24 ,8 ,-1 ,0 ,0 ,0x0008 ,SUN1999_HWID }, + }, + }, +}; + +static const char snx_ser_ic_table[SNX_SER_PORT_MAX_UART ][10 ] = { + {"UNKNOWN" }, + {"SUN1889" }, + {"SUN1699" }, + {"SUNMATX" }, + {"SUN1999" } +}; + +static const char snx_par_ic_table[SNX_PAR_PORT_MAX_UART ][10 ] = { + {"UNKNOWN" }, + {"SUN1888" }, + {"SUN1689" }, + {"SUNMATX" }, + {"SUN1999" } +}; + +static const char snx_port_remap[2 ][10 ] = { + {"NON-REMAP" }, + {"REMAP" } +}; + +enum { +// golden-serial +GOLDEN_BOARD_TEST =0 , + +// matrix-serial +MATRIX_BOARD_P1002 , +MATRIX_BOARD_P1004 , +MATRIX_BOARD_P1008 , +MATRIX_BOARD_P1016 , +MATRIX_BOARD_P2002 , +MATRIX_BOARD_P2004 , +MATRIX_BOARD_P2008 , +MATRIX_BOARD_P3002 , +MATRIX_BOARD_P3004 , +MATRIX_BOARD_P3008 , + +// sun1999-serial RS232 +SUN1999_BOARD_5027A , +SUN1999_BOARD_5037A , +SUN1999_BOARD_5056A , +SUN1999_BOARD_5066A , +SUN1999_BOARD_5016A , + +//sun1999-multi I/O +SUN1999_BOARD_5069A , +SUN1999_BOARD_5079A , +SUN1999_BOARD_5099A , + +//sun1999-parallel + +SUN1999_BOARD_5008A , + +//sun1999-serial RS422/485 +SUN1999_BOARD_P2102 , +SUN1999_BOARD_P2104 , +SUN1999_BOARD_P2108 , +SUN1999_BOARD_P2116 , + +//sun1999 3_in_1 +SUN1999_BOARD_P3104 , +SUN1999_BOARD_P3108 , + +//cash drawer card +SUN1999_BOARD_CASH_2S , +SUN1999_BOARD_CASH_4S , + +//DIO +SUN1999_BOARD_DIO0802 , +SUN1999_BOARD_DIO1604 , +SUN1999_BOARD_DIO3204 , + +}; + +static const struct pci_device_id sunix_pci_board_id[] = { +// golden-serial + {VENID_GOLDEN ,DEVID_G_SERIAL ,SUBVENID_GOLDEN , +SUBDEVID_TEST ,0 ,0 ,GOLDEN_BOARD_TEST }, + +// matrix-serial + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1002 ,0 ,0 ,MATRIX_BOARD_P1002 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1004 ,0 ,0 ,MATRIX_BOARD_P1004 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1008 ,0 ,0 ,MATRIX_BOARD_P1008 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P1016 ,0 ,0 ,MATRIX_BOARD_P1016 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P2002 ,0 ,0 ,MATRIX_BOARD_P2002 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P2004 ,0 ,0 ,MATRIX_BOARD_P2004 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P2008 ,0 ,0 ,MATRIX_BOARD_P2008 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P3002 ,0 ,0 ,MATRIX_BOARD_P3002 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P3004 ,0 ,0 ,MATRIX_BOARD_P3004 }, + {VENID_MATRIX ,DEVID_M_SERIAL ,SUBVENID_MATRIX , +SUBDEVID_P3008 ,0 ,0 ,MATRIX_BOARD_P3008 }, + +// sun1999-serial RS232 + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5027A ,0 ,0 ,SUN1999_BOARD_5027A }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5037A ,0 ,0 ,SUN1999_BOARD_5037A }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5056A ,0 ,0 ,SUN1999_BOARD_5056A }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5066A ,0 ,0 ,SUN1999_BOARD_5066A }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5016A ,0 ,0 ,SUN1999_BOARD_5016A }, + +// sun1999-multi I/O + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5069A ,0 ,0 ,SUN1999_BOARD_5069A }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5079A ,0 ,0 ,SUN1999_BOARD_5079A }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_5099A ,0 ,0 ,SUN1999_BOARD_5099A }, + +// sun1999-parallel + {VENID_SUN1999 ,DEVID_S_PARALL ,SUBVENID_SUN1999 , +SUBDEVID_5008A ,0 ,0 ,SUN1999_BOARD_5008A }, + +// sun1999-serial RS422/485 + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_P2102 ,0 ,0 ,SUN1999_BOARD_P2102 }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_P2104 ,0 ,0 ,SUN1999_BOARD_P2104 }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_P2108 ,0 ,0 ,SUN1999_BOARD_P2108 }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_P2116 ,0 ,0 ,SUN1999_BOARD_P2116 }, + +// sun1999 3_in_1 + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_P3104 ,0 ,0 ,SUN1999_BOARD_P3104 }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_P3108 ,0 ,0 ,SUN1999_BOARD_P3108 }, + +//cash drawer card 2S + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_CASH_2S ,0 ,0 ,SUN1999_BOARD_CASH_2S }, + +//cash drawer card 4S + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_CASH_4S ,0 ,0 ,SUN1999_BOARD_CASH_4S }, + +//DIO + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_DIO0802 ,0 ,0 ,SUN1999_BOARD_DIO0802 }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_DIO1604 ,0 ,0 ,SUN1999_BOARD_DIO1604 }, + {VENID_SUN1999 ,DEVID_S_SERIAL ,SUBVENID_SUN1999 , +SUBDEVID_DIO3204 ,0 ,0 ,SUN1999_BOARD_DIO3204 }, + + {0 } +}; +MODULE_DEVICE_TABLE (pci, sunix_pci_board_id); + +struct sunix_board sunix_board_table[SNX_BOARDS_MAX ]; +struct sunix_ser_port sunix_ser_table[SNX_SER_TOTAL_MAX +1 ]; +struct sunix_par_port sunix_par_table[SNX_PAR_TOTAL_MAX ]; + +static int snx_ser_port_total_cnt; +static int snx_par_port_total_cnt; + +int snx_board_count; + +static struct snx_ser_driver sunix_ser_reg = { + .dev_name ="ttySNX" , + .major =0 , + .minor =0 , + .nr = (SNX_SER_TOTAL_MAX +1 ), +}; + +static irqreturn_t sunix_interrupt (int irq,void *dev_id) +{ +struct sunix_ser_port *sp =NULL ; +struct sunix_par_port *pp =NULL ; +struct sunix_board *sb =NULL ; +int i; +int status =0 ; + +int handled =IRQ_NONE ; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + +if (dev_id == &(sunix_board_table[i])) { + sb = dev_id; +break ; + } + } + +if (i ==SNX_BOARDS_MAX ) + status =1 ; + +if (!sb) + status =1 ; + +if (sb->board_enum <=0 ) + status =1 ; + +if (status !=0 ) +return handled; + +if ((sb->ser_port >0 ) && (sb->ser_isr !=NULL )) { + sp = &sunix_ser_table[sb->ser_port_index]; + +if (!sp) + status =1 ; + + status = sb->ser_isr (sb, sp); + } + +if ((sb->par_port >0 ) && (sb->par_isr !=NULL )) { + pp = &sunix_par_table[sb->par_port_index]; + +if (!pp) + status =1 ; + + status = sb->par_isr (sb, pp); + } + +if (status !=0 ) +return handled; + + handled =IRQ_HANDLED ; +return handled; +} + +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 ; + + termios = &tty->termios; + + 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_ser_port *sp) +{ +struct snx_ser_port *port = &sp->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_board *sb =pci_get_drvdata (pdev); +struct sunix_ser_port *sp =NULL ; +int j; + +if (sb ==NULL ) +return 0 ; + +for (j =0 ; j < sb->ser_port; j++) { + sp = &sunix_ser_table[j]; + +if (sp ==NULL ) +return 0 ; + +if (sp->port.suspended ==1 ) +snx_resume_port (sp); + } + +return 0 ; +} + + +static int sunix_pci_board_probe (void ) +{ +struct sunix_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 boardcnt; +int i; +unsigned short int sub_device_id; +unsigned short int device_part_number; +unsigned int bar3_base_add; + +int status; +unsigned int bar3_Byte5; +unsigned int bar3_Byte6; +unsigned int bar3_Byte7; +unsigned int oem_id; +unsigned char uart_type; +unsigned char gpio_type; +unsigned char gpio_card_type; +int gpio_ch_cnt; + +// clear and init some variable +memset (sunix_board_table,0 ,SNX_BOARDS_MAX * +sizeof (struct sunix_board )); + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sunix_board_table[i].board_enum =-1 ; + sunix_board_table[i].board_number =-1 ; + } + + sunix_pci_board_id_cnt = + (sizeof (sunix_pci_board_id) /sizeof (sunix_pci_board_id[0 ])) -1 ; + +// search matrix serial board + pdev =NULL ; + tablecnt =0 ; + boardcnt =0 ; + sub_device_id =0 ; + status =0 ; + +while (tablecnt < sunix_pci_board_id_cnt) { + + pdev =pci_get_device (VENID_MATRIX ,DEVID_M_SERIAL , pdev); + +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 ) { + status = -EIO ; +return status; + } + +if (sub_device_id != sunix_pci_board_id[tablecnt].subdevice) +continue ; +if (pdev ==NULL ) { +pr_err ("SNX Error: PCI device object is NULL !\n" ); + status = -EIO ; +return status; + + }else { + + status =pci_enable_device (pdev); + +if (status !=0 ) { +pr_err ("SNX Error: SUNIX Board Enable Fail !\n\n" ); + status = -ENXIO ; +return status; + } + } + + boardcnt++; +if (boardcnt >SNX_BOARDS_MAX ) { +pr_err ("SNX Error: Support Four Boards In Maximum !\n" ); + status = -ENOSPC ; +return status; + } + + sb = &sunix_board_table[boardcnt-1 ]; + pdev_array[boardcnt-1 ] = pdev; + sb->pdev = pdev; + sb->bus_number = pdev->bus->number; + sb->dev_number =PCI_SLOT (pdev->devfn); + sb->board_enum = (int )sunix_pci_board_id[tablecnt].driver_data; + sb->pb_info = snx_pci_board_conf[sb->board_enum]; + sb->board_flag = sb->pb_info.board_flag; + sb->board_number = boardcnt -1 ; + } + +// search sun1999 muti I/O board + pdev =NULL ; + tablecnt =0 ; + sub_device_id =0 ; + status =0 ; + device_part_number =0 ; + bar3_base_add =0 ; + bar3_Byte5 =0 ; + bar3_Byte6 =0 ; + bar3_Byte7 =0 ; + oem_id =0 ; + uart_type =0 ; + gpio_type =0 ; + gpio_card_type =0 ; + gpio_ch_cnt =0 ; + +while (tablecnt < sunix_pci_board_id_cnt) { + + pdev =pci_get_device (VENID_SUN1999 ,DEVID_S_SERIAL , pdev); + +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 ) { + status = -EIO ; +return status; + } + +if (sub_device_id != sunix_pci_board_id[tablecnt].subdevice) +continue ; + +if (pdev ==NULL ) { +pr_err ("SNX Error: PCI device object is an NULL pointer !\n\n" ); + status = -EIO ; +return status; + + }else { + + status =pci_enable_device (pdev); + +if (status !=0 ) { +pr_err ("SNX Error: SUNIX Board Enable Fail !\n\n" ); + status = -ENXIO ; +return status; + } + } + + bar3_base_add =pci_resource_start (pdev,3 ); + device_part_number =inb (bar3_base_add +5 ); + bar3_Byte5 = device_part_number; + bar3_Byte6 =inb (bar3_base_add +0x06 ); + bar3_Byte7 =inb (bar3_base_add +0x07 ); + gpio_card_type = ((bar3_Byte7 &0x18 )>>3 ); + oem_id = (bar3_Byte5 | (bar3_Byte6 <<8 ) | (bar3_Byte7 <<16 )); + uart_type = ((bar3_Byte5 &0xc0 )>>6 ); + gpio_ch_cnt = ((bar3_Byte7 &0x60 )>>5 ); + gpio_type = ((bar3_Byte7 &0x80 )>>7 ); + +if ((gpio_ch_cnt ==0x00 ) && (gpio_card_type ==0x01 )) + gpio_ch_cnt =6 ; +else if ((gpio_ch_cnt ==0x00 ) && (gpio_card_type ==0x02 )) + gpio_ch_cnt =8 ; +else if (gpio_ch_cnt ==0x01 ) + gpio_ch_cnt =16 ; +else if (gpio_ch_cnt ==0x02 ) + gpio_ch_cnt =32 ; + +if (device_part_number != snx_pci_board_conf[tablecnt].part_number) +continue ; +else if (gpio_card_type != snx_pci_board_conf[tablecnt].card_type) +continue ; +else if (gpio_ch_cnt != snx_pci_board_conf[tablecnt].gpio_ch_cnt) +continue ; +else +pr_err ("\n" ); + + boardcnt++; +if (boardcnt >SNX_BOARDS_MAX ) { +pr_err ("SNX Error: Support Four Boards In Maximum !\n" ); + status = -ENOSPC ; +return status; + } + + sb = &sunix_board_table[boardcnt-1 ]; + pdev_array[boardcnt-1 ] = pdev; + sb->pdev = pdev; + sb->bus_number = pdev->bus->number; + sb->dev_number =PCI_SLOT (pdev->devfn); + sb->board_enum = (int )sunix_pci_board_id[tablecnt].driver_data; + sb->pb_info = snx_pci_board_conf[sb->board_enum]; + sb->board_flag = sb->pb_info.board_flag; + sb->board_number = boardcnt -1 ; + sb->oem_id = oem_id; + sb->uart_cnt = sb->pb_info.num_serport; + sb->gpio_chl_cnt = gpio_ch_cnt; + sb->board_uart_type = uart_type; + sb->board_gpio_card_type = gpio_card_type; + sb->board_gpio_type = gpio_type; + + } + +// search SUN1999 parallel board + pdev =NULL ; + tablecnt =0 ; + sub_device_id =0 ; + status =0 ; + +while (tablecnt < sunix_pci_board_id_cnt) { + + pdev =pci_get_device (VENID_SUN1999 ,DEVID_S_PARALL , pdev); + +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 ) { + status = -EIO ; +return status; + } + +if (sub_device_id != sunix_pci_board_id[tablecnt].subdevice) +continue ; + +if (pdev ==NULL ) { +pr_err ("SNX Error: PCI device object is an NULL pointer !\n\n" ); + status = -EIO ; +return status; + + }else { + + status =pci_enable_device (pdev); + +if (status !=0 ) { +pr_err ("SNX Error: SUNIX Board Enable Fail !\n\n" ); + status = -ENXIO ; +return status; + } + } + + boardcnt++; +if (boardcnt >SNX_BOARDS_MAX ) { +pr_err ("\n" ); +pr_err ("SNX Error: SUNIX Driver Module Support Four Boards In Maximum !\n\n" ); + status = -ENOSPC ; +return status; + } + + sb = &sunix_board_table[boardcnt-1 ]; + pdev_array[boardcnt-1 ] = pdev; + sb->pdev = pdev; + sb->bus_number = pdev->bus->number; + sb->dev_number =PCI_SLOT (pdev->devfn); + sb->board_enum = (int )sunix_pci_board_id[tablecnt].driver_data; + sb->pb_info = snx_pci_board_conf[sb->board_enum]; + sb->board_flag = sb->pb_info.board_flag; + sb->board_number = boardcnt -1 ; + } + +// print info +if (boardcnt ==0 ) { +pr_err ("SNX Info : No SUNIX Multi-I/O Board Found !\n\n" ); + status = -ENXIO ; +return status; + + }else { + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i]; + +if (sb->board_enum >0 ) { +pr_err ("\n" ); + +if ((sb->pb_info.num_serport >0 ) && + (sb->pb_info.num_parport >0 )) { +pr_err ("SNX Info : Found SUNIX %s Series Board (%dS%dP),\n" , + sb->pb_info.board_name, + sb->pb_info.num_serport, + sb->pb_info.num_parport); + }else if ((sb->pb_info.num_serport) >0 ) { +pr_err ("SNX Info : Found SUNIX %s Series Board (%dS),\n" , + sb->pb_info.board_name, + sb->pb_info.num_serport); + }else { +pr_err ("SNX Info : Found SUNIX %s Series Board (%dP),\n" , + sb->pb_info.board_name, + sb->pb_info.num_parport); + } +pr_err (" bus number:%d, device number:%d\n\n" , + sb->bus_number, sb->dev_number); + } + } + snx_board_count = boardcnt; + } + +return status; +} + + +static int sunix_get_pci_board_conf (void ) +{ +struct sunix_board *sb =NULL ; +struct pci_dev *pdev =NULL ; +int status =0 ; +int i; +int j; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i]; + +if (sb->board_enum >0 ) { + pdev = sb->pdev; + sb->ports = sb->pb_info.num_serport + + sb->pb_info.num_parport; + sb->ser_port = sb->pb_info.num_serport; + sb->par_port = sb->pb_info.num_parport; + snx_ser_port_total_cnt = snx_ser_port_total_cnt + + sb->ser_port; + snx_par_port_total_cnt = snx_par_port_total_cnt + + sb->par_port; + +if (snx_ser_port_total_cnt >SNX_SER_TOTAL_MAX ) { +pr_err ("SNX Error: Too much serial port\n" ); + status = -EIO ; +return status; + } + +if (snx_par_port_total_cnt >SNX_PAR_SUPPORT_MAX ) { +pr_err ("SNX Error: Too much parallel port\n" ); + status = -EIO ; +return status; + } + +for (j =0 ; j <SNX_PCICFG_BAR_TOTAL ; j++) + sb->bar_addr[j] =pci_resource_start (pdev, j); + + + sb->irq = sb->pdev->irq; + +if (sb->irq <=0 ) { +pr_err ("SNX Error: SUNIX Board %s Series (bus:%d device:%d), in configuartion space, irq isn't valid !\n\n" , + sb->pb_info.board_name, + sb->bus_number, + sb->dev_number); + + status = -EIO ; +return status; + } + } + } + +return status; +} + + +static int sunix_assign_resource (void ) +{ +struct sunix_board *sb =NULL ; +struct sunix_ser_port *sp =NULL ; +struct sunix_par_port *pp =NULL ; + +int status =0 ; +int i; +int j; +int k; +int ser_n; +int ser_port_index =0 ; + +memset (sunix_ser_table,0 , (SNX_SER_TOTAL_MAX +1 ) * +sizeof (struct sunix_ser_port )); + +memset (sunix_par_table,0 , (SNX_PAR_TOTAL_MAX ) * +sizeof (struct sunix_par_port )); + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i]; + +if (sb->board_enum >0 ) { +if (sb->ser_port >0 ) { + sb->vector_mask =0 ; + +// assign serial port resource + ser_n = sb->ser_port_index = ser_port_index; + + sp = &sunix_ser_table[ser_n]; + +if (sp ==NULL ) { + status = -ENXIO ; +pr_err ("SNX Error: Serial port table address error !\n" ); +return status; + } + +for (j =0 ; j < sb->ser_port; j++, ser_n++, sp++) { + sp->port.chip_flag = sb->pb_info.port[j].chip_flag; + sp->port.iobase = sb->bar_addr[ + sb->pb_info.port[j].bar1] + + sb->pb_info.port[j].offset1; + +if ((sb->board_flag &BOARDFLAG_REMAP ) == +BOARDFLAG_REMAP ) { + sp->port.vector =0 ; + sb->vector_mask =0x00 ; + }else { + sp->port.vector = sb->bar_addr[ + sb->pb_info.intr_vector_bar] + + sb->pb_info.intr_vector_offset; + sb->vector_mask |= (1 << j); + } + } + + ser_port_index = ser_port_index + sb->ser_port; + } + + +// assign parallel port resource +if (sb->par_port >0 ) { + k =0 ; + +for (j =0 ; j <SNX_PAR_TOTAL_MAX ; j++) { +if ((k +1 ) > sb->par_port) +break ; + +if (j >=SNX_PAR_TOTAL_MAX ) { + status = -EACCES ; +pr_err ("SNX Error: Too much parallel port!\n" ); +return status; + } + + pp = &sunix_par_table[j]; + +if (pp ==NULL ) { + status = -ENXIO ; +pr_err ("SNX Error: Parallel port table address error !\n" ); +return status; + } + +if (pp->chip_flag !=SUNNONE_HWID ) { +continue ; + }else { + pp->chip_flag = sb->pb_info.port[k + + sb->ser_port].chip_flag; + + pp->base = sb->bar_addr[ + sb->pb_info.port[k + + sb->ser_port].bar1] + + sb->pb_info.port[k + + sb->ser_port].offset1; + + pp->base_hi = sb->bar_addr[ + sb->pb_info.port[k + + sb->ser_port].bar2] + + sb->pb_info.port[k + + sb->ser_port].offset2; + + pp->bus_number = sb->bus_number; + pp->dev_number = sb->dev_number; + pp->board_enum = sb->board_enum; + k++; + } + } + } + } + } + +return status; +} + + +static int sunix_ser_port_table_init (void ) +{ +struct sunix_board *sb =NULL ; +struct sunix_ser_port *sp =NULL ; +int status =0 ; +int i; +int j; +int n; +int AHDC_State =0 ; +int RS422_State =0 ; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i]; + +if (sb ==NULL ) { + status = -ENXIO ; +pr_err ("SNX Error: Board table pointer error !\n" ); +return status; + } + +if ((sb->board_enum >0 ) && (sb->ser_port >0 )) { + n = sb->ser_port_index; + sp = &sunix_ser_table[n]; + +if (sp ==NULL ) { + status = -ENXIO ; +pr_err ("SNX Error: Serial port table pointer error !\n" ); +return status; + } + +for (j =0 ; j < sb->ser_port; j++, n++, sp++) { +if (j <4 ) { + AHDC_State =inb (sb->bar_addr[3 ]+2 ) &0x0F & + (0x01 << (((j+1 )-1 ) %4 )); + RS422_State =inb (sb->bar_addr[3 ]+3 ) & +0xF0 & (0x10 << (((j+1 )-1 ) %4 )); + }else if (j <8 ) { + AHDC_State =inb (sb->bar_addr[1 ] +0x32 ) & +0x0F & (0x01 << (((j+1 )-1 ) %4 )); + RS422_State =inb (sb->bar_addr[1 ] +0x33 ) & +0xF0 & (0x10 << (((j+1 )-1 ) %4 )); + } + + RS422_State = ((RS422_State &0xF0 ) >>4 ); + sp->port.AHDC_State = AHDC_State >> (((j+1 )-1 )%4 ); + sp->port.RS422_State = RS422_State >> (((j+1 )-1 )%4 ); + + sp->port.board_enum = sb->board_enum; + sp->port.bus_number = sb->bus_number; + sp->port.dev_number = sb->dev_number; + sp->port.baud_base =921600 ; + sp->port.pb_info = sb->pb_info; + sp->port.irq = sb->irq; + sp->port.line = n; + sp->port.uartclk = sp->port.baud_base *16 ; + sp->port.iotype =SNX_UPIO_PORT ; + sp->port.flags =ASYNC_SHARE_IRQ ; + sp->port.ldisc_stop_rx =0 ; +spin_lock_init (&sp->port.lock); + +if (sp->port.chip_flag ==SUN1889_HWID ) { + sp->port.snx_type =SNX_SER_PORT_SUN1889 ; + sp->port.type =PORT_SER_16650V2 ; + sp->port.fifosize =SUN1889_FIFOSIZE_SET ; + sp->port.rx_trigger =SUN1889_TRIGGER_LEVEL_SET ; + }else if (sp->port.chip_flag ==SUN1699_HWID ) { + sp->port.snx_type =SNX_SER_PORT_SUN1699 ; + sp->port.type =PORT_SER_16650V2 ; + sp->port.fifosize =SUN1699_FIFOSIZE_SET ; + sp->port.rx_trigger =SUN1699_TRIGGER_LEVEL_SET ; + }else if (sp->port.chip_flag ==SUNMATX_HWID ) { + sp->port.snx_type =SNX_SER_PORT_SUNMATX ; + sp->port.type =PORT_SER_16750 ; + sp->port.fifosize =SUNMATX_FIFOSIZE_SET ; + sp->port.rx_trigger =SUNMATX_TRIGGER_LEVEL_SET ; + }else if (sp->port.chip_flag ==SUN1999_HWID ) { + sp->port.snx_type =SNX_SER_PORT_SUN1999 ; + sp->port.type =PORT_SER_16750 ; + sp->port.fifosize =SUN1999_FIFOSIZE_SET ; + sp->port.rx_trigger =SUN1999_TRIGGER_LEVEL_SET ; + }else { + sp->port.snx_type =SNX_SER_PORT_UNKNOWN ; + sp->port.type =PORT_SER_16450 ; + sp->port.fifosize =DEFAULT_FIFOSIZE ; + sp->port.rx_trigger =DEFAULT_TRIGGER_LEVEL ; + } + + +if ((sb->pb_info.board_flag & +BOARDFLAG_REMAP ) ==BOARDFLAG_REMAP ) { + sp->port.vector_mask =0 ; + sp->port.port_flag =PORTFLAG_REMAP ; + }else { + sp->port.vector_mask = sb->vector_mask; + sp->port.port_flag =PORTFLAG_NONE ; + } + +if ((sb->pb_info.board_flag & +BOARDFLAG_16PORTS ) ==BOARDFLAG_16PORTS ) + sp->port.port_flag |=PORTFLAG_16PORTS ; + + + sp->port.setserial_flag =SNX_SER_BAUD_NOTSETSER ; + } + + sb->ser_isr = sunix_ser_interrupt; + }else { + sb->ser_isr =NULL ; + } + } + + +// release io resource +for (i =0 ; i <SNX_SER_TOTAL_MAX ; i++) { + sp = &sunix_ser_table[i]; + +if (sp->port.iobase >0 ) +release_region (sp->port.iobase,SNX_SER_ADDRESS_LENGTH ); + + } +return status; +} + + +static int sunix_par_port_table_init (void ) +{ +struct sunix_board *sb =NULL ; +struct sunix_par_port *pp =NULL ; +int status =0 ; +int i; +int j; +int k; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i]; + +if (sb ==NULL ) { + status = -ENXIO ; +pr_err ("SNX Error: Board table pointer error !\n" ); +return status; + } + +if ((sb->board_enum >0 ) && (sb->par_port >0 )) { + k =0 ; +for (j =0 ; j <SNX_PAR_TOTAL_MAX ; j++) { + pp = &sunix_par_table[j]; + +if (pp ==NULL ) { + status = -ENXIO ; +pr_err ("SNX Error: Parallel port tablepointer error\n" ); +return status; + } + +if ((k +1 ) > sb->par_port) +break ; + +if ((pp->bus_number == sb->bus_number) && + (pp->dev_number == sb->dev_number) && + (pp->board_enum == sb->board_enum)) { + + pp->pb_info = sb->pb_info; + pp->irq =PARPORT_IRQ_NONE ; + pp->portnum = j; + +if (pp->chip_flag ==SUN1888_HWID ) { + pp->snx_type = +SNX_PAR_PORT_SUN1888 ; + }else if (pp->chip_flag == +SUN1689_HWID ) { + pp->snx_type = +SNX_PAR_PORT_SUN1689 ; + }else if (pp->chip_flag == +SUNMATX_HWID ) { + pp->snx_type = +SNX_PAR_PORT_SUNMATX ; + }else if (pp->chip_flag == +SUN1999_HWID ) { + pp->snx_type = +SNX_PAR_PORT_SUN1999 ; + }else { + pp->snx_type = +SNX_PAR_PORT_UNKNOWN ; + } + +if ((sb->pb_info.board_flag & +BOARDFLAG_REMAP ) == +BOARDFLAG_REMAP ) { + pp->port_flag =PORTFLAG_REMAP ; + }else { + pp->port_flag =PORTFLAG_NONE ; + } + sb->par_isr =NULL ; + k++; + } + } + } + } + + +// release io resource +for (i =0 ; i <SNX_PAR_TOTAL_MAX ; i++) { + pp = &sunix_par_table[i]; + +if (pp->base >0 ) { +release_region (pp->base,SNX_PAR_ADDRESS_LENGTH ); + + +release_region (pp->base,SNX_PAR_STD_ADDR_LENGTH ); + +release_region (pp->base + +SNX_PAR_STD_ADDR_LENGTH , +SNX_PAR_ETD_ADDR_LENGTH ); + +if (pp->base_hi >0 ) { +release_region (pp->base_hi, +SNX_PAR_ADDRESS_LENGTH ); + +release_region (pp->base_hi, +SNX_PAR_STD_ADDR_LENGTH ); + +release_region (pp->base_hi + +SNX_PAR_STD_ADDR_LENGTH , +SNX_PAR_ETD_ADDR_LENGTH ); + } + } + } + +return status; +} + +int sunix_register_irq (void ) +{ +struct sunix_board *sb =NULL ; +int status =0 ; +int i; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i]; + +if (sb ==NULL ) { + status = -ENXIO ; +pr_err ("SNX Error: Board table pointer error !\n" ); +return status; + } + +if (sb->board_enum >0 ) { + status =request_irq (sb->irq, + sunix_interrupt, +IRQF_SHARED , +"snx" , sb); + +if (status) { +pr_err ("SNX Error: SUNIX Multi-I/O %s Board(bus:%d device:%d), request\n" , + sb->pb_info.board_name, + sb->bus_number, + sb->dev_number); +pr_err (" 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_board *sb =NULL ; +int i; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i]; + +if (sb->board_enum >0 ) +free_irq (sb->irq, sb); + } +} + + +static int snx_pci_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +return 0 ; +} + +static struct pci_driver snx_pci_driver = { + .name ="snx" , + .probe = snx_pci_probe, + .suspend = snx_suspend_one, + .resume = snx_resume_one, + .id_table = sunix_pci_board_id, +}; + +static int __init snx_init (void ) +{ +int status =0 ; + + snx_ser_port_total_cnt = snx_par_port_total_cnt =0 ; + + status =sunix_pci_board_probe (); +if (status !=0 ) + goto step1_fail; + + status =sunix_get_pci_board_conf (); +if (status !=0 ) + goto step1_fail; + + + status =sunix_assign_resource (); +if (status !=0 ) + goto step1_fail; + + + status =sunix_ser_port_table_init (); +if (status !=0 ) + goto step1_fail; + + + status =sunix_par_port_table_init (); +if (status !=0 ) + goto step1_fail; + + + status =sunix_register_irq (); +if (status !=0 ) + goto step1_fail; + + + status =sunix_ser_register_driver (&sunix_ser_reg); +if (status !=0 ) + goto step2_fail; + + status =sunix_ser_register_ports (&sunix_ser_reg); +if (status !=0 ) + goto step3_fail; + + status =pci_register_driver (&snx_pci_driver); +if (status !=0 ) + goto step7_fail; + +if (snx_par_port_total_cnt >0 ) { + status =sunix_par_parport_init (); +if (status !=0 ) + goto step4_fail; + + status =sunix_par_ppdev_init (); +if (status !=0 ) + goto step5_fail; + + status =sunix_par_lp_init (); +if (status !=0 ) + goto step6_fail; + + } + +#if SNX_DBG +sunix_debug (); +#endif + +return status; + + +if (snx_par_port_total_cnt >0 ) { +step7_fail: + +pci_unregister_driver (&snx_pci_driver); + +step6_fail: + +sunix_par_ppdev_exit (); + +step5_fail: + +sunix_par_parport_exit (); + +step4_fail: + +sunix_ser_unregister_ports (&sunix_ser_reg); + } + +step3_fail: + +sunix_ser_unregister_driver (&sunix_ser_reg); + + +step2_fail: + +sunix_release_irq (); + + +step1_fail: + +pr_err ("SNX Error: Couldn't Loading SUNIX Multi-I/O Board Driver Module correctly,\n" ); +pr_err (" please reboot system and try again. If still can't loading driver,\n" ); +pr_err (" contact support.\n\n" ); + +return status; +} + + +static void __exit snx_exit(void) +{ +if (snx_par_port_total_cnt >0 ) { +sunix_par_lp_exit (); + +sunix_par_ppdev_exit (); + +sunix_par_parport_exit (); + } + +sunix_ser_unregister_ports (&sunix_ser_reg); + +sunix_ser_unregister_driver (&sunix_ser_reg); + +sunix_release_irq (); +pci_unregister_driver (&snx_pci_driver); +pr_err ("SNX Info : Unload SUNIX Multi-I/O Board Driver Module Done.\n" ); +} + +module_init (snx_init); +module_exit (snx_exit); +
mfd/sunix/snx_serial.c new file +3513 -0
1,329 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Quoted 6 lines · Morris Ku
Driver for SUNIX Multi-I/O card.
Based ondriver/char/serial.cby Linus Torvalds, Theodore Ts'o.SUNIX serial card designed with SUNIX UART controller and compatible with 16C950 UART specification.
<snip>
Quoted 1 line
+static const char snx_ser_ic_table[SNX_SER_PORT_MAX_UART][10] = {
Doesn't seem to be used anywhere.
mfd/sunix/snx_main.c line 465
Quoted 8 lines
mfd/sunix/snx_main.c new file +8
-0+ {"UNKNOWN"}, + {"SUN1889"}, + {"SUN1699"}, + {"SUNMATX"}, + {"SUN1999"} +}; + +static const char snx_par_ic_table[SNX_PAR_PORT_MAX_UART ][10 ] = {
Doesn't seem to be used anywhere.
mfd/sunix/snx_main.c line 473
Quoted 9 lines
mfd/sunix/snx_main.c new file +8
-0+ {"UNKNOWN"}, + {"SUN1888"}, + {"SUN1689"}, + {"SUNMATX"}, + {"SUN1999"} +}; + +static const char snx_port_remap[2 ][10 ] = {
Doesn't seem to be used anywhere.
Quoted 3 lines
mfd/sunix/snx_main.c new file +3
-0+ {"NON-REMAP"}, + {"REMAP"} +};
<snip>
mfd/sunix/snx_main.c line 620
Quoted 3 lines
mfd/sunix/snx_main.c new file +3
-0+struct sunix_board sunix_board_table[SNX_BOARDS_MAX ]; +struct sunix_ser_port sunix_ser_table[SNX_SER_TOTAL_MAX +1 ]; +struct sunix_par_port sunix_par_table[SNX_PAR_TOTAL_MAX ];
Allocate these per-device (per card) in sunix_pci_board_probe() and let the device's private_data point to it.
And better do static zero initialization instead of memset().
<snip>
mfd/sunix/snx_main.c line 632
Quoted 6 lines
mfd/sunix/snx_main.c new file +6
-0+static struct snx_ser_driver sunix_ser_reg = { + .dev_name ="ttySNX" , + .major =0 , + .minor =0 , + .nr = (SNX_SER_TOTAL_MAX +1 ), +};
Why this struct for something that exists only once and still allocating more (struct snx_ser_state) in sunix_ser_register_driver() ? Why not just putting everything into one struct ?
mfd/sunix/snx_main.c line 646
Quoted 13 lines
mfd/sunix/snx_main.c new file +13
-0+static irqreturn_t sunix_interrupt (int irq,void *dev_id) +{ +struct sunix_ser_port *sp =NULL ; +struct sunix_par_port *pp =NULL ; +struct sunix_board *sb =NULL ; +int i; +int status =0 ; + +int handled =IRQ_NONE ; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + +if (dev_id == &(sunix_board_table[i])) {
Don't do unncessary loops in time sensitive functions. Instead pass the pointer to the corresponding struct sunix_board via dev_id - it's the second parameter of request_irq(). Would make the code much simpler and smaller.
Quoted 6 lines
mfd/sunix/snx_main.c new file +6
-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 ;
mfd/sunix/snx_main.c line 709
Quoted 10 lines
mfd/sunix/snx_main.c new file +10
-0+ + termios = &tty->termios; + + retval =snx_ser_startup (state,0 ); + +if (retval ==0 ) +snx_ser_update_termios (state); + +return 0 ; +}
Don't duplicate already existing functionality - use the serial subsystem. See: drivers/tty/serial/
Quoted 27 lines
mfd/sunix/snx_main.c new file +27
-0+static int sunix_pci_board_probe (void ) +{ +struct sunix_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 boardcnt; +int i; +unsigned short int sub_device_id; +unsigned short int device_part_number; +unsigned int bar3_base_add; + +int status; +unsigned int bar3_Byte5; +unsigned int bar3_Byte6; +unsigned int bar3_Byte7; +unsigned int oem_id; +unsigned char uart_type; +unsigned char gpio_type; +unsigned char gpio_card_type; +int gpio_ch_cnt; + +// clear and init some variable +memset (sunix_board_table,0 ,SNX_BOARDS_MAX * +sizeof (struct sunix_board ));
mfd/sunix/snx_main.c line 791
Quoted 10 lines
mfd/sunix/snx_main.c new file +8
-0+ +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sunix_board_table[i].board_enum =-1 ; + sunix_board_table[i].board_number =-1 ; + } + + sunix_pci_board_id_cnt = + (sizeof (sunix_pci_board_id) /sizeof (sunix_pci_board_id[0 ])) -1 ;
use ARRAY_SIZE() here.
mfd/sunix/snx_main.c line 798
Quoted 7 lines
mfd/sunix/snx_main.c new file +7
-0+ +// search matrix serial board + pdev =NULL ; + tablecnt =0 ; + boardcnt =0 ; + sub_device_id =0 ; + status =0 ;
Do the initialization at declaration.
mfd/sunix/snx_main.c line 802
Quoted 3 lines
mfd/sunix/snx_main.c new file +3
-0+while (tablecnt < sunix_pci_board_id_cnt) { + + pdev =pci_get_device (VENID_MATRIX ,DEVID_M_SERIAL , pdev);
Use separate per-board driver instances instead of one instance for all. Using multiple cards won't work this way - probe() is called per card.
Quoted 5 lines
mfd/sunix/snx_main.c new file +5
-0+// search sun1999 muti I/O board + pdev =NULL ; + tablecnt =0 ; + sub_device_id =0 ; + status =0 ;
mfd/sunix/snx_main.c line 873
Quoted 10 lines
mfd/sunix/snx_main.c new file +10
-0+ device_part_number =0 ; + bar3_base_add =0 ; + bar3_Byte5 =0 ; + bar3_Byte6 =0 ; + bar3_Byte7 =0 ; + oem_id =0 ; + uart_type =0 ; + gpio_type =0 ; + gpio_card_type =0 ; + gpio_ch_cnt =0 ;
Use separate driver instances for that.
mfd/sunix/snx_main.c line 877
Quoted 3 lines
mfd/sunix/snx_main.c new file +3
-0+while (tablecnt < sunix_pci_board_id_cnt) { + + pdev =pci_get_device (VENID_SUN1999 ,DEVID_S_SERIAL , pdev);
again: multiple cards won't work that way. you'll overwrite the structures of the previous cards.
mfd/sunix/snx_main.c line 976
Quoted 5 lines
mfd/sunix/snx_main.c new file +5
-0+// search SUN1999 parallel board + pdev =NULL ; + tablecnt =0 ; + sub_device_id =0 ; + status =0 ;
use a separate driver for that.
Quoted 8 lines
mfd/sunix/snx_main.c new file +8
-0+static int sunix_assign_resource (void ) +{ +struct sunix_board *sb =NULL ; +struct sunix_ser_port *sp =NULL ; +struct sunix_par_port *pp =NULL ; + +int status =0 ; +int i;
mfd/sunix/snx_main.c line 1153
Quoted 10 lines
mfd/sunix/snx_main.c new file +10
-0+int j; +int k; +int ser_n; +int ser_port_index =0 ; + +memset (sunix_ser_table,0 , (SNX_SER_TOTAL_MAX +1 ) * +sizeof (struct sunix_ser_port )); + +memset (sunix_par_table,0 , (SNX_PAR_TOTAL_MAX ) * +sizeof (struct sunix_par_port ));
See above: use static zero initialization.
mfd/sunix/snx_main.c line 1290
Quoted 12 lines
mfd/sunix/snx_main.c new file +12
-0+for (j =0 ; j < sb->ser_port; j++, n++, sp++) { +if (j <4 ) { + AHDC_State =inb (sb->bar_addr[3 ]+2 ) &0x0F & + (0x01 << (((j+1 )-1 ) %4 )); + RS422_State =inb (sb->bar_addr[3 ]+3 ) & +0xF0 & (0x10 << (((j+1 )-1 ) %4 )); + }else if (j <8 ) { + AHDC_State =inb (sb->bar_addr[1 ] +0x32 ) & +0x0F & (0x01 << (((j+1 )-1 ) %4 )); + RS422_State =inb (sb->bar_addr[1 ] +0x33 ) & +0xF0 & (0x10 << (((j+1 )-1 ) %4 )); + }
can't the register space be memory-mapped ?
mfd/sunix/snx_main.c line 1485
Quoted 7 lines
mfd/sunix/snx_main.c new file +7
-0+int sunix_register_irq (void ) +{ +struct sunix_board *sb =NULL ; +int status =0 ; +int i; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) {
use separate per-board device instances.
mfd/sunix/snx_main.c line 1522
Quoted 7 lines
mfd/sunix/snx_main.c new file +7
-0+void sunix_release_irq (void ) +{ +struct sunix_board *sb =NULL ; +int i; + +for (i =0 ; i <SNX_BOARDS_MAX ; i++) { + sb = &sunix_board_table[i];
use separate per-board device instances.
otherwise hotplug won't work.
mfd/sunix/snx_main.c line 1552
Quoted 10 lines
mfd/sunix/snx_main.c new file +10
-0+static int __init snx_init (void ) +{ +int status =0 ; + + snx_ser_port_total_cnt = snx_par_port_total_cnt =0 ; + + status =sunix_pci_board_probe (); +if (status !=0 ) + goto step1_fail; +
register the drivers first. the pci subsystem will then probe automatically. (and call the driver's probe() function per board).
mfd/sunix/snx_serial.c line 844
Quoted 12 lines
mfd/sunix/snx_serial.c new file +12
-0+if (!capable (CAP_SYS_ADMIN )) { + retval = -EPERM ; +if (change_irq || + change_port || + (new_serial.baud_base != port->uartclk /16 ) || + (close_delay != state->close_delay) || + (closing_wait != state->closing_wait) || + (new_serial.xmit_fifo_size != port->fifosize) || + (((new_flags ^ old_flags) + & ~SNX_UPF_USR_MASK ) !=0 )) { + goto exit; + }
As already said: changing things like irqs or io areaas from userland shouldn't be possible at all by such weird ways. Let the corresponding bus subsystems (in that case: pci) handle it in generic ways, and care for probing and hotplug. (anyways, it seems that this doesn't change the irq the device is raising, just the one the driver expects - that's even more wrong)
mfd/sunix/snx_serial.c line 901
Quoted 5 lines
mfd/sunix/snx_serial.c new file +5
-0+if (port->flags &SNX_UPF_SPD_MASK ) { +pr_info ("SNX Info : %s sets custom speed " , + current->comm); +pr_info ("on ttySNX%d. This is deprecated.\n" , + port->line);
Why do you newly introduce things that are already deprecated ?
Quoted 10 lines
mfd/sunix/snx_serial.c new file +10
-0+static int snx_ser_ioctl (struct tty_struct *tty, +unsigned int cmd,unsigned long arg) +{ +struct snx_ser_state *state =NULL ; +int ret = -ENOIOCTLCMD ; +int line =SNX_SER_DEVNUM (tty); + +if (line <SNX_SER_TOTAL_MAX ) + state = tty->driver_data; +
mfd/sunix/snx_serial.c line 1171
Quoted 10 lines
mfd/sunix/snx_serial.c new file +10
-0+ +switch (cmd) { +case TIOCGSERIAL : + { +if (line <SNX_SER_TOTAL_MAX ) + ret =snx_ser_get_info (state, + (struct serial_struct *)arg); + +break ; + }
Dont reimplement existing standard functionality in your own special way. Use the serial subsystem instead.
Quoted 31 lines
mfd/sunix/snx_serial.c new file +31
-0+case SNX_SER_DUMP_PORT_INFO : + { +int i; +struct snx_ser_port_info snx_port_info[SNX_SER_TOTAL_MAX ]; +struct snx_ser_port *sdn =NULL ; + +memset (snx_port_info,0 , + (sizeof (struct snx_ser_port_info ) * +SNX_SER_TOTAL_MAX )); + +if (line ==0 ) { +for (i =0 ; i <SNX_SER_TOTAL_MAX ; i++) { + sdn = (struct snx_ser_port *) + &sunix_ser_table[i]; + +memcpy (&snx_port_info[i].board_name_info[0 ], + &sdn->pb_info.board_name[0 ], +SNX_BOARDNAME_LENGTH ); + + snx_port_info[i].bus_number_info = + sdn->bus_number; + snx_port_info[i].dev_number_info = + sdn->dev_number; + snx_port_info[i].port_info = sdn->line; + snx_port_info[i].base_info = sdn->iobase; + snx_port_info[i].irq_info = sdn->irq; + } + +if (copy_to_user ((void *)arg, snx_port_info, +SNX_SER_TOTAL_MAX *sizeof (struct snx_ser_port_info ))) + ret = -EFAULT ;
mfd/sunix/snx_serial.c line 1246
Quoted 10 lines
mfd/sunix/snx_serial.c new file +10
-0+else + ret =0 ; + + }else { + ret =0 ; + } + + ret =0 ; +break ; + }
This doesn't belong here. Don't invent your own private ioctl's for such things. Use sysfs or debugfs.
mfd/sunix/snx_serial.c line 1249
Quoted 3 lines
mfd/sunix/snx_serial.c new file +3
-0+ +case SNX_SER_DUMP_DRIVER_VER : + {
Same here.
mfd/sunix/snx_serial.c line 1274
Quoted 2 lines
mfd/sunix/snx_serial.c new file +2
-0+case SNX_COMM_GET_BOARD_CNT : + {
No, This information can already be retrieved just by the number of serial/tty devices. Anyways this is just metadata for the admin, nothing that client applications should have to care about.
mfd/sunix/snx_serial.c line 1293
Quoted 2 lines
mfd/sunix/snx_serial.c new file +2
-0+case SNX_COMM_GET_BOARD_INFO : + {
See above: use debugfs or sysfs if you have to publish extra metadata.
mfd/sunix/snx_serial.c line 1325
Quoted 2 lines
mfd/sunix/snx_serial.c new file +2
-0+case SNX_UART_GET_TYPE : + {
Don't reimplement existing standard functionality.
mfd/sunix/snx_serial.c line 1430
Quoted 4 lines
mfd/sunix/snx_serial.c new file +4
-0+case SNX_UART_SET_TYPE : { +struct sunix_board *sb =NULL ; +struct sunix_ser_port *sp =NULL ; +
what things exactly can be set here, that aren't already handled by the standard serial subsystem ?
mfd/sunix/snx_serial.c line 1478
Quoted 2 lines
mfd/sunix/snx_serial.c new file +2
-0+ GPIOstate =inb (targetConfigAddress +0x0C ); + GPIOcontrol =inb (targetConfigAddress +0x0D );
GPIOs don't belong here. We have a separate GPIO subsystem.
mfd/sunix/snx_serial.c line 1652
Quoted 5 lines
mfd/sunix/snx_serial.c new file +5
-0+case SNX_UART_GET_ACS : + { +SNX_DRVR_UART_GET_ACS gb; +struct sunix_board *sb =NULL ; +int ACSstate =0 ;
What kind of states are these exactly that aren't already handled by the standard serial subsystem ?
Quoted 1 line
+extern void
snx_ser_update_termios(struct snx_ser_state *state)
Why do you need "extern" here?
Quoted 12 lines
mfd/sunix/snx_serial.c new file +12
-0+static const struct tty_operations sunix_tty_ops = { + .open = snx_ser_open, + .close = snx_ser_close, + .write = snx_ser_write, + .put_char = snx_ser_put_char, + .flush_chars = snx_ser_flush_chars, + .write_room = snx_ser_write_room, + .chars_in_buffer = snx_ser_chars_in_buffer, + .flush_buffer = snx_ser_flush_buffer, + .ioctl = snx_ser_ioctl, + .throttle = snx_ser_throttle, + .unthrottle = snx_ser_unthrottle,
mfd/sunix/snx_serial.c line 3060
Quoted 10 lines
mfd/sunix/snx_serial.c new file +10
-0+ .send_xchar = snx_ser_send_xchar, + .set_termios = snx_ser_set_termios, + .stop = snx_ser_stop, + .start = snx_ser_start, + .hangup = snx_ser_hangup, + .break_ctl = snx_ser_break_ctl, + .wait_until_sent = snx_ser_wait_until_sent, + .tiocmget = snx_ser_tiocmget, + .tiocmset = snx_ser_tiocmset, +};
Don't reimplement existing functionality - use the serial subsystem.
Quoted 21 lines
mfd/sunix/snx_serial.c new file +21
-0+static int sunix_ser_add_one_port (struct snx_ser_driver *drv, +struct snx_ser_port *port) +{ +struct snx_ser_state *state =NULL ; +struct tty_port *tport; +struct device *tty_dev; + +int ret =0 ; + +if (port->line >= drv->nr) +return -EINVAL ; + + state = drv->state + port->line; + + tport = &state->tport; + +down (&ser_port_sem); + +if (state->port) { + ret = -EINVAL ; + goto out;
mfd/sunix/snx_serial.c line 3246
Quoted 10 lines
mfd/sunix/snx_serial.c new file +10
-0+ } + + state->port = port; + + port->info = state->info; + +sunix_ser_configure_port (drv, state, port); + + tty_dev =tty_port_register_device ( + tport, snx_driver, port->line, port->dev);
Dont reimplement existing functionality - use the serial subsystem.
Your driver is at least 10 times bigger as it needs to be, reimplements lots of standard functionality in own private ways and bypasses the corresponding subsystems. I could never ack that.
--mtx
Signature · 3 lines
Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Quoted 5 lines · Morris Ku
Driver for SUNIX Multi-I/O card.
Based ondriver/char/serial.cby Linus Torvalds, Theodore Ts'o.SUNIX serial card designed with SUNIX UART controller and compatible with 16C950 UART specification.
Serial drivers should live in drivers/tty/serial.
Please move it there.
Quoted 7 lines
Signed-off-by Morris Ku <[email protected]>--- mfd/sunix/snx_main.c | 1671 +++++++++++++++++++ mfd/sunix/snx_serial.c | 3513 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 5184 insertions(+) create mode 100644 mfd/sunix/snx_main.c create mode 100644 mfd/sunix/snx_serial.c
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog