Add Driver for SUNIX PCI(e) I/O expansion board
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
@@ -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/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.
Quoted 1 line · Moriis Ku
From: Morris <[email protected]>
Full names please.
Quoted 1 line
The board provide UART, DIO and CAN functions.
This commit message is not adequate for a 12k line patch.
Quoted 17 lines
Signed-off-by Morris <[email protected]>--- 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
Quoted 8 lines
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
I'm just going to conduct a high-level pass on this presently.
drivers/mfd/bus.c
Quoted 6 lines
drivers/mfd/bus.c new file +0
-0@@ -0,0 +1,1524 @@
Missing SPDXs.
drivers/mfd/bus.c line 2
Quoted 2 lines
drivers/mfd/bus.c new file +2
-0+/* +* Driver for SUNIX PCI(e) expansion board
Omit the leading ' 's please.
drivers/mfd/bus.c line 8
Quoted 6 lines
drivers/mfd/bus.c new file +6
-0+* 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.
Omit this. It's replaced by the SPDX.
drivers/mfd/bus.c line 11
Quoted 3 lines
drivers/mfd/bus.c new file +3
-0+*/ + +
No double line spacing.
drivers/mfd/bus.c line 15
Quoted 4 lines
drivers/mfd/bus.c new file +4
-0+#include "sdc_include.h" + + +#if (LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,0 ))
This will never be in the 2.6 kernel. Please omit all of these.
Quoted 19 lines
drivers/mfd/bus.c new file +19
-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[] = +{
drivers/mfd/bus.c line 44
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+ {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];
No forward declarations. Please reorder the code instead.
drivers/mfd/bus.c line 52
Quoted 7 lines
drivers/mfd/bus.c new file +7
-0+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;
Avoid global variables like the plague.
Quoted 15 lines
drivers/mfd/bus.c new file +15
-0+ +#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 ;
drivers/mfd/bus.c line 78
Quoted 10 lines
drivers/mfd/bus.c new file +10
-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++) + {
Please read and understand the Coding Style document.
Documentation/process/coding-style.rst
drivers/mfd/bus.c line 87
Quoted 9 lines
drivers/mfd/bus.c new file +9
-0+if (dev_id == &(sunix_sdc_board_table[i])) + { + sb = dev_id; +break ; + } + } + +if (i ==SUNIX_SDC_BOARD_MAX ) + status =1 ;
No magic numbers. Please define them.
Quoted 14 lines
drivers/mfd/bus.c new file +14
-0+ +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
drivers/mfd/bus.c line 111
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+ } + + 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 );
Loop?
drivers/mfd/bus.c line 121
Quoted 9 lines
drivers/mfd/bus.c new file +9
-0+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;
You're going to need to comment all of this.
drivers/mfd/bus.c line 129
Quoted 7 lines
drivers/mfd/bus.c new file +7
-0+ 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
Coding style: No C++ comments.
drivers/mfd/bus.c line 130
Quoted 1 line
drivers/mfd/bus.c new file +1
-0+ if ((uart_chl->port.iobase != 0) &&
Wayyyyy to many indentations. Please reorganise the code.
Quoted 55 lines
drivers/mfd/bus.c new file +55
-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 + } +
drivers/mfd/bus.c line 195
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+#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 ;
Why does this exist?
Quoted 17 lines
drivers/mfd/bus.c new file +17
-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) +{ +} + + +static int snx_resume_port_termios (struct snx_ser_info *info) +{ +}
drivers/mfd/bus.c line 267
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+ + +static int snx_resume_port (struct sunix_sdc_uart_channel *uart_chl) +{ +} + + +static int snx_resume_one (struct pci_dev *pdev) +{ +}
These needs to be moved to Serial.
drivers/mfd/bus.c line 534
Quoted 3 lines
drivers/mfd/bus.c new file +3
-0+static int sunix_get_pci_board_conf (void ) +{ +}
This needs moving to PCI.
drivers/mfd/bus.c line 1124
Quoted 8 lines
drivers/mfd/bus.c new file +8
-0+static int sunix_dio_channel_table_init (void ) +{ +} + + +static void sunix_dio_channel_table_deinit (void ) +{ +}
I don't know what DIO is in this context, but it's likely that it needs to be moved to Pinctrl/GPIO (maybe?).
drivers/mfd/bus.c line 1270
Quoted 8 lines
drivers/mfd/bus.c new file +8
-0+static int sunix_spi_channel_table_init (void ) +{ +} + + +static void sunix_spi_channel_table_deinit (void ) +{ +}
Move to SPI.
Quoted 26 lines
drivers/mfd/bus.c new file +26
-0+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)
drivers/mfd/bus.c line 1324
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+ { +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; +}
This seems over-complicated just to request an IRQ.
Quoted 95 lines
drivers/mfd/bus.c new file +95
-0+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); +
drivers/mfd/bus.c line 1487
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+step3_fail: +kmem_cache_destroy (sunix_sdc_spi_pack_cache); + +step2_fail: +kmem_cache_destroy (sunix_sdc_dio_pack_cache); + +step1_fail: + +return status; +}
I think you're mixing up _init with _probe.
_init should be very short and simple.
Quoted 14 lines
drivers/mfd/bus.c new file +14
-0+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 (); +
drivers/mfd/bus.c line 1513
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+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); +}
Use _remove instead of _exit.
drivers/mfd/bus.c line 1520
Quoted 5 lines
drivers/mfd/bus.c new file +5
-0+module_init (sunix_sdc_init); +module_exit (sunix_sdc_exit); + + +MODULE_AUTHOR ("SUNIX Co., Ltd.<[email protected]>" );
This is not an author.
drivers/mfd/dio.c
Quoted 8 lines
drivers/mfd/bus.c new file +2
-0+MODULE_DESCRIPTION ("SUNIX PCI(e) expansion board bus driver" ); +MODULE_LICENSE ("GPL" );drivers/mfd/dio.c new file +0
-0
This needs moving to Pinctrl/GPIO.
drivers/mfd/dio_pack.c
Quoted 5 lines
drivers/mfd/dio_pack.c new file +0
-0
I don't even know what to make of this.
[...]
drivers/mfd/dio_pack.c line 234
Quoted 2 lines
drivers/mfd/dio_pack.c new file +2
-0+ InputDeltaReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,1 ); +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 1, InputDeltaReg:x%08x\n", dio_chl->info.line, InputDeltaReg);
No unused code.
drivers/mfd/spi.c
Quoted 12 lines
drivers/mfd/dio_pack.c new file +7
-0+ InputDeltaReg &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 2, InputDeltaReg:x%08x\n", dio_chl->info.line, InputDeltaReg); + InputDeltaReg &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 3, InputDeltaReg:x%08x\n", dio_chl->info.line, InputDeltaReg); + BankDeltaState = InputDeltaReg >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 4, BankDeltaState:x%08x\n", dio_chl->info.line, BankDeltaState); + }index 000000000000..4c7c1c494255
drivers/mfd/spi.c new file +0
-0
Please move to SPI.
drivers/mfd/spi_pack.c
Quoted 3 lines
index 000000000000..ff49e0ae94ac
drivers/mfd/spi_pack.c new file +0
-0
Please move to SPI
drivers/mfd/uart.c
Quoted 3 lines
index 000000000000..bb88630fdca1
drivers/mfd/uart.c new file +0
-0
Please move to UART.
[...]
Okay ... so ... where to begin?!
Essentially, upstreaming 12k lines of non-conformant code is a no-go.
Where did you get this from? One of the down-stream repos?
Please provide more information in the commit message. Writing a single line commit message for a 12k line patch is not doing it the justice that it deserves. We want to know it's history, where it came from, what it does (in detail), what hardware it runs on, what your plans are for it i.e. why you're going to the effort of upstreaming it in the first place, etc.
I'll make no bones about it. If you want to get these driver*S* upstream, you are in this for the long haul. Most of this needs splitting up into its component parts; MFD, PCI, UART, SPI, Pinctrl, etc, and will require a re-write at most levels.
My suggestion would be to start small. Strip the whole thing down to the smallest piece of 'functional' code (code that does something useful) that you can, upstream that, then build on it incrementally.
I wish you the very best of luck.
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
On 30.03.21 08:58, Moriis Ku wrote:
Hi folks,
Quoted 3 lines
From: Morris <[email protected]>
The board provide UART, DIO and CAN functions.
Oh no, not again ... we had about a hundred mails about the same thing (at least the quite same device), many month ago. And it seems really much of what had been said these days, wasn't taken account for :(
Quoted 32 lines
Signed-off-by Morris <[email protected]>--- 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 100644drivers/mfd/dio.c
create mode 100644drivers/mfd/dio_pack.c
create mode 100644drivers/mfd/list.c
create mode 100644drivers/mfd/mem.c
create mode 100644drivers/mfd/sdc_define.h
create mode 100644drivers/mfd/sdc_function.h
create mode 100644drivers/mfd/sdc_include.h
create mode 100644drivers/mfd/spi.c
create mode 100644drivers/mfd/spi_pack.c
create mode 100644drivers/mfd/uart.cdrivers/mfd/bus.c new file +0
-0
drivers/mfd/bus.c line 9
Quoted 9 lines
drivers/mfd/bus.c new file +9
-0@@ -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. +*/
Use spdx headers instead.
drivers/mfd/bus.c line 15
Quoted 4 lines
drivers/mfd/bus.c new file +4
-0+#include "sdc_include.h" + + +#if (LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,0 ))
Certainly not. We don't carry around dead code pieces for ancient kernel versions. Please also make sure that your code really aligns to the _current_ kernel, using helpers and infrastructure that had been developed in the last decade ...
I doubt that anybody here seriously wants to read such code.
Quoted 19 lines
drivers/mfd/bus.c new file +19
-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[] = +{
drivers/mfd/bus.c line 44
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+ {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];
Nope, never add such global fields. Per-Device data belongs into proper struct in device's privdata ...
Quoted 4 lines
drivers/mfd/bus.c new file +4
-0+ +struct kmem_cache * sunix_sdc_dio_pack_cache; +struct kmem_cache * sunix_sdc_spi_pack_cache; +
drivers/mfd/bus.c line 58
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+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
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+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 ))
drivers/mfd/bus.c line 79
Quoted 10 lines
drivers/mfd/bus.c new file +10
-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]))
OMGS! No, give the irq a pointer to the device, not some table index. And drop that global table completely.
Quoted 50 lines
drivers/mfd/bus.c new file +50
-0+ { + 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
drivers/mfd/bus.c line 139
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+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); + } + }
Really too deep nesting, to big function. Split it.
Quoted 47 lines
drivers/mfd/bus.c new file +47
-0+ +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 ))
drivers/mfd/bus.c line 196
Quoted 10 lines
drivers/mfd/bus.c new file +10
-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 ; +}
What is that for ?
Quoted 106 lines
drivers/mfd/bus.c new file +106
-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; + +
drivers/mfd/bus.c line 312
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+// 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 ; + }
drop this global table. put it into device privdata.
Quoted 6 lines
drivers/mfd/bus.c new file +6
-0+ sunix_pci_board_id_cnt = (sizeof (sunix_pci_board_id) /sizeof (sunix_pci_board_id[0 ])) -1 ; + + +// search + pdev =NULL ; + tablecnt =0 ;
drivers/mfd/bus.c line 328
Quoted 10 lines
drivers/mfd/bus.c new file +10
-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
No, dont do this scan that manually. Make it a pci driver and register it to the pci subsystem with ID table.
Quoted 157 lines
drivers/mfd/bus.c new file +157
-0+ +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;
drivers/mfd/bus.c line 495
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+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++) + {
drop that global table.
Quoted 189 lines
drivers/mfd/bus.c new file +189
-0+ 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 );
drivers/mfd/bus.c line 694
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+ status = -EIO ; +return status; + } + } + } + + + + +#if (ENABLE_DEBUG_SDC_BUS ==1 )
where does that symbol come from ?
Quoted 12 lines
drivers/mfd/bus.c new file +12
-0+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);
drivers/mfd/bus.c line 716
Quoted 10 lines
drivers/mfd/bus.c new file +10
-0+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);
certainly not such raw printk()'s (even w/o loglevels) in a driver.
Quoted 845 lines
drivers/mfd/bus.c new file +808
-0+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 +31
-0@@ -0,0 +1,529 @@ + + +#include "sdc_include.h" + + +static int sunix_dio_open (struct inode *inode,struct file *file) +{ +int line =MINOR (file->f_path.dentry->d_inode->i_rdev); +struct sunix_sdc_dio_channel *dio_chl =NULL ; +int status =0 ; + + + do + { + if (line > SUNIX_SDC_DIO_MAX) + { + status = -ENODEV; + break; + } + dio_chl = &sunix_sdc_dio_table[line]; + if (dio_chl->info.memsize == 0) + { + status = -ENODEV; + break; + } + if (dio_chl->isOpened == true) + { + status = -EBUSY; + break; + } +
drivers/mfd/dio.c line 41
Quoted 10 lines
drivers/mfd/dio.c new file +10
-0+ + dio_chl->InputInvertEnableReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,2 ); + dio_chl->InputLatchRegPositiveEdgeR =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,3 ); + dio_chl->InputLatchRegNegativeEdgeR =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,4 ); + dio_chl->InputCounterIncrementCtrlRegPositiveEdge =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,6 ); + dio_chl->InputCounterIncrementCtrlRegNegativeEdge =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,7 ); + dio_chl->InputRisingEventCtrlReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,8 ); + dio_chl->InputFallingEventCtrlReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,9 ); + dio_chl->DirectionCtrlReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,12 ); + dio_chl->OutputInitialValueReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,13 );
Why a completely own, proprietary character device, instead of just pluggin into gpio (or IIO, if its a streaming DIO) subsystem ?
drivers/mfd/list.c
Quoted 3,724 lines
drivers/mfd/dio.c new file +488
-0+ + dio_chl->readDataReady =0 ; + dio_chl->isOpened = true; + +#if (LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,0 )) +try_module_get (THIS_MODULE ); +#else +MOD_INC_USE_COUNT ; +#endif + + }while (false); + +return status; +} + + +static int sunix_dio_release (struct inode *inode,struct file *file) +{ +int line =MINOR (file->f_path.dentry->d_inode->i_rdev); +struct sunix_sdc_dio_channel *dio_chl =NULL ; +int status =0 ; +DLIST * pListHead =NULL ; +DLIST * e =NULL ; +unsigned long Flags; +PDIO_PACKAGE pPack =NULL ; + + +do + { +if (line >SUNIX_SDC_DIO_MAX ) + { + status = -ENODEV ; +break ; + } + dio_chl = &sunix_sdc_dio_table[line]; +if (dio_chl->info.memsize ==0 ) + { + status = -ENODEV ; +break ; + } +if (dio_chl->isOpened == false) + { + status = -ENODEV ; +break ; + } + + pListHead = &dio_chl->packList; +spin_lock_irqsave (&dio_chl->packLock, Flags); +while (!SxxListEmpty (pListHead)) + { + e =SxxListGetNext (pListHead); + pPack =SUNIX_SDC_DIO_PACK_PTR (e); +if (pPack !=NULL ) + { +printk ("SUNIX: DIO FREE pack, line:%d, pack:x%p, DataPtrx%p\n" , dio_chl->info.line, pPack, pPack->DataPtr); +SxxListRemoveEntry (e); +if (pPack->DataPtr !=NULL ) + { +kfree (pPack->DataPtr); + pPack->DataPtr =NULL ; + } +kmem_cache_free (sunix_sdc_dio_pack_cache, pPack); + pPack =NULL ; + } + } +spin_unlock_irqrestore (&dio_chl->packLock, Flags); + + dio_chl->isOpened = false; + +#if (LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,0 )) +module_put (THIS_MODULE ); +#else +MOD_DEC_USE_COUNT ; +#endif + + }while (false); + +return status; +} + + +static long sunix_dio_ioctl (struct file *file,unsigned int cmd,unsigned long arg) +{ +int line =MINOR (file->f_path.dentry->d_inode->i_rdev); +struct sunix_sdc_dio_channel *dio_chl =NULL ; +int status =0 ; + + +do + { +if (line >SUNIX_SDC_DIO_MAX ) + { + status = -ENODEV ; +break ; + } + dio_chl = &sunix_sdc_dio_table[line]; +if (dio_chl->info.memsize ==0 ) + { + status = -ENODEV ; +break ; + } +if (dio_chl->isOpened == false) + { + status = -ENODEV ; +break ; + } + + }while (false); + +return status; +} + + +static ssize_t sunix_dio_read (struct file *file,char __user *buf,size_t count,loff_t *offset) +{ +int line =MINOR (file->f_path.dentry->d_inode->i_rdev); +struct sunix_sdc_dio_channel *dio_chl =NULL ; +int status =0 ; +unsigned int outcomeLength =0 ; + + +if (line >SUNIX_SDC_DIO_MAX ) + { +return -ENODEV ; + } + dio_chl = &sunix_sdc_dio_table[line]; +if (dio_chl->info.memsize ==0 ) + { +return -ENODEV ; + } +if (dio_chl->isOpened == false) + { +return -ENODEV ; + } + +if (count <sizeof (DIO_HEADER )) + { +return -ENOMEM ; + } + + +if (down_interruptible (&dio_chl->sem)) + { +return -ERESTARTSYS ; + } + +if (dio_chl->readDataReady ==0 ) + { +up (&dio_chl->sem); + +if ((file->f_flags &O_NONBLOCK )) + { +return -EAGAIN ; + } + +wait_event_interruptible (dio_chl->readWQ, dio_chl->readDataReady ==1 ); + +if (down_interruptible (&dio_chl->sem)) + { +return -ERESTARTSYS ; + } + } + + +do + { + status =sunix_dio_handle_outcome (dio_chl, count, &outcomeLength); +if (status !=0 ) + { +break ; + } +if (count < outcomeLength) + { + status = -ENOMEM ; +break ; + } +if (outcomeLength <=0 ) + { + status =0 ; +break ; + } + +if (copy_to_user ((void *)buf, dio_chl->outcomeBuff, outcomeLength)) + { + status = -EFAULT ; +break ; + } + + status = outcomeLength; + + }while (false); + + + dio_chl->readDataReady =0 ; +up (&dio_chl->sem); + +return status; +} + + +static ssize_t sunix_dio_write (struct file *file,const char __user *buf,size_t count,loff_t *offset) +{ +int line =MINOR (file->f_path.dentry->d_inode->i_rdev); +struct sunix_sdc_dio_channel *dio_chl =NULL ; +int status =0 ; + + +do + { +if (line >SUNIX_SDC_DIO_MAX ) + { + status = -ENODEV ; +break ; + } + dio_chl = &sunix_sdc_dio_table[line]; +if (dio_chl->info.memsize ==0 ) + { + status = -ENODEV ; +break ; + } +if (dio_chl->isOpened == false) + { + status = -ENODEV ; +break ; + } + +if (count <sizeof (DIO_HEADER )) + { + status = -EFAULT ; +break ; + } + +if (count > (sizeof (DIO_HEADER ) +DIO_MAX_DATA_LENGTH )) + { + status = -ENOMEM ; +break ; + } + +if (copy_from_user (dio_chl->incomeBuff, (void *)buf, count)) + { + status = -EFAULT ; +break ; + } + + status =sunix_dio_handle_income (dio_chl, count); +if (status ==0 ) + { + status = count; + } + + }while (false); + +return status; +} + + +unsigned int sunix_dio_poll (struct file *file,poll_table *wait) +{ +int line =MINOR (file->f_path.dentry->d_inode->i_rdev); +struct sunix_sdc_dio_channel *dio_chl =NULL ; +unsigned int mask =POLLOUT |POLLWRNORM ; + + +do + { +if (line >SUNIX_SDC_DIO_MAX ) + { + mask = -ENODEV ; +break ; + } + dio_chl = &sunix_sdc_dio_table[line]; +if (dio_chl->info.memsize ==0 ) + { + mask = -ENODEV ; +break ; + } +if (dio_chl->isOpened == false) + { + mask = -ENODEV ; +break ; + } + + +down (&dio_chl->sem); + +poll_wait (file, &dio_chl->readWQ, wait); + +if (dio_chl->readDataReady ==1 ) + { + mask |= (POLLIN |POLLRDNORM ); + } + +up (&dio_chl->sem); + + }while (false); + +return mask; +} + + +static int sunix_dio_uevent (struct device *dev,struct kobj_uevent_env *env) +{ +add_uevent_var (env,"DEVMODE=%#o" ,0666 ); +return 0 ; +} + + +static const struct file_operations sunix_sdc_dio_fops = +{ + .owner =THIS_MODULE , + .open = sunix_dio_open, + .release = sunix_dio_release, + .unlocked_ioctl = sunix_dio_ioctl, + .read = sunix_dio_read, + .write = sunix_dio_write, + .poll = sunix_dio_poll +}; + + +static int sunix_sdc_dio_dev_major =0 ; +static struct class *sunix_sdc_dio_dev_class =NULL ; + + +int sunix_dio_register_channel (void ) +{ +int err, i; +dev_t dev; +struct sunix_sdc_dio_channel *dio_chl =NULL ; + + + err =alloc_chrdev_region (&dev,0 , sunix_sdc_dio_amount,"sunix_sdc_dio" ); +if (err !=0 ) + { +return err; + } + + sunix_sdc_dio_dev_major =MAJOR (dev); + + sunix_sdc_dio_dev_class =class_create (THIS_MODULE ,"sunix_sdc_dio" ); + sunix_sdc_dio_dev_class->dev_uevent = sunix_dio_uevent; + +for (i =0 ; i < sunix_sdc_dio_amount; i++) + { + dio_chl = &sunix_sdc_dio_table[i]; +if ((dio_chl !=NULL ) && (dio_chl->info.membase !=NULL )) + { +request_mem_region (dio_chl->info.phy2_base_start + dio_chl->info.memoffset, dio_chl->info.memsize,"sunix_sdc_dio" ); + +cdev_init (&dio_chl->cdev, &sunix_sdc_dio_fops); + dio_chl->cdev.owner =THIS_MODULE ; + +cdev_add (&dio_chl->cdev,MKDEV (sunix_sdc_dio_dev_major, i),1 ); + +device_create (sunix_sdc_dio_dev_class,NULL ,MKDEV (sunix_sdc_dio_dev_major, i),NULL ,"SDCDIO%d" , i); + } + } + +return 0 ; +} + + +void sunix_dio_unregister_channel (void ) +{ +int i; +struct sunix_sdc_dio_channel *dio_chl =NULL ; + + +for (i =0 ; i < sunix_sdc_dio_amount; i++) + { + dio_chl = &sunix_sdc_dio_table[i]; +if ((dio_chl !=NULL ) && (dio_chl->info.membase !=NULL )) + { +device_destroy (sunix_sdc_dio_dev_class,MKDEV (sunix_sdc_dio_dev_major, i)); + +release_mem_region (dio_chl->info.phy2_base_start + dio_chl->info.memoffset, dio_chl->info.memsize); + } + } + +class_unregister (sunix_sdc_dio_dev_class); +class_destroy (sunix_sdc_dio_dev_class); + +unregister_chrdev_region (MKDEV (sunix_sdc_dio_dev_major,0 ),MINORMASK ); +} + + +int sunix_dio_interrupt (struct sunix_sdc_dio_channel *dio_chl,unsigned int event_header) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +unsigned int InputValue =0 ; +unsigned int BankInputValue =0 ; +unsigned int BankInputDelta =0 ; +int i =0 ; +unsigned char TxBuff[256 ]; +unsigned int TxLength =0 ; +PDIO_HEADER pTxHeader = (PDIO_HEADER )TxBuff; +PDIO_PACKAGE pPack =NULL ; +bool bCreatePackSuccess = false; +unsigned long Flags; + + + InputValue =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,0 ); + +for (i =0 ; i < cib_info->dio_number_of_banks; i++) + { +if ((cib_info->dio_bank_cap[i].io_mask & event_header) && (cib_info->dio_bank_cap[i].support_inputs ==0x01 )) + { + BankInputValue = ((InputValue & cib_info->dio_bank_cap[i].io_mask) >> cib_info->dio_bank_cap[i].io_shift_bits); + BankInputDelta = ((event_header & cib_info->dio_bank_cap[i].io_mask) >> cib_info->dio_bank_cap[i].io_shift_bits); + + +memset (TxBuff,0 ,sizeof (TxBuff)); + TxLength =0 ; + + pTxHeader->Version =0x01 ; + pTxHeader->CmdResponseEventData =SDCDIO_EVENT ; + pTxHeader->ResponseStatus =SDCDIO_STATUS_SUCCESS ; + pTxHeader->Length =9 ; + TxLength =sizeof (DIO_HEADER ); + + TxBuff[TxLength++] = i; + + TxBuff[TxLength++] = (unsigned char )((BankInputDelta &0xff000000 ) >>24 ); + TxBuff[TxLength++] = (unsigned char )((BankInputDelta &0x00ff0000 ) >>16 ); + TxBuff[TxLength++] = (unsigned char )((BankInputDelta &0x0000ff00 ) >>8 ); + TxBuff[TxLength++] = (unsigned char )((BankInputDelta &0x000000ff )); + + TxBuff[TxLength++] = (unsigned char )((BankInputValue &0xff000000 ) >>24 ); + TxBuff[TxLength++] = (unsigned char )((BankInputValue &0x00ff0000 ) >>16 ); + TxBuff[TxLength++] = (unsigned char )((BankInputValue &0x0000ff00 ) >>8 ); + TxBuff[TxLength++] = (unsigned char )((BankInputValue &0x000000ff )); + + +do + { + pPack =NULL ; + bCreatePackSuccess = false; + + pPack =kmem_cache_alloc (sunix_sdc_dio_pack_cache,GFP_ATOMIC ); +if (pPack ==NULL ) + { +break ; + } +memset (pPack,0 ,sizeof (DIO_PACKAGE )); + + pPack->DataPtr = (unsigned char *)kmalloc (DIO_MAX_DATA_LENGTH ,GFP_KERNEL ); +if (pPack->DataPtr ==NULL ) + { +break ; + } +memset (pPack->DataPtr,0 ,DIO_MAX_DATA_LENGTH ); + +SxxListInit (&pPack->Entry); +memcpy (&pPack->Header, pTxHeader,sizeof (DIO_HEADER )); +memcpy (pPack->DataPtr, TxBuff +sizeof (DIO_HEADER ), pTxHeader->Length); + +spin_lock_irqsave (&dio_chl->packLock, Flags); +//printk("SUNIX: DIO ALOC pack, line:%d, pack:x%p, DataPtrx%p\n", dio_chl->info.line, pPack, pPack->DataPtr); +SxxListInsertTail (&dio_chl->packList, &pPack->Entry); + + dio_chl->readDataReady =1 ; +wake_up_interruptible (&dio_chl->readWQ); +spin_unlock_irqrestore (&dio_chl->packLock, Flags); + + bCreatePackSuccess = true; + + }while (false); + +if (bCreatePackSuccess == false) + { +if (pPack !=NULL ) + { +if (pPack->DataPtr !=NULL ) + { +kfree (pPack->DataPtr); + pPack->DataPtr =NULL ; + } + +kmem_cache_free (sunix_sdc_dio_pack_cache, pPack); + pPack =NULL ; + } + } + } + } + +return 0 ; +} + +drivers/mfd/dio_pack.c new file +3126
-0@@ -0,0 +1,3126 @@ + + +#include "sdc_include.h" + + +static void get_info (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned int Address =0 ; +int i =0 ; +unsigned int BankDirection =0 ; + + +do + { + Address = dio_chl->info.phy2_base_start + dio_chl->info.memoffset; + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?(28 + (cib_info->dio_number_of_banks *18 )):0 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { +memcpy (&TrBuff[TrLength], dio_chl->info.model_name,16 ); + TrLength +=16 ; + TrBuff[TrLength++] = dio_chl->info.bus_number; + TrBuff[TrLength++] = dio_chl->info.dev_number; + TrBuff[TrLength++] = dio_chl->info.line; + TrBuff[TrLength++] = (unsigned char )((Address &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((Address &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((Address &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((Address &0x000000ff )); + TrBuff[TrLength++] = (unsigned char )(dio_chl->info.irq); + + TrBuff[TrLength++] = cib_info->version; + TrBuff[TrLength++] = cib_info->dio_number_of_banks; + TrBuff[TrLength++] = cib_info->dio_shares_same_direction_ctrl_cap; + TrBuff[TrLength++] = cib_info->dio_writing_setting_to_flash_cap; + +for (i =0 ; i < cib_info->dio_number_of_banks; i++) + { + BankDirection = (dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[i].io_mask) >>cib_info->dio_bank_cap[i].io_shift_bits; + + TrBuff[TrLength++] = i; + TrBuff[TrLength++] = cib_info->dio_bank_cap[i].number_of_io; + TrBuff[TrLength++] = cib_info->dio_bank_cap[i].support_inputs; + TrBuff[TrLength++] = cib_info->dio_bank_cap[i].support_outputs; + TrBuff[TrLength++] = cib_info->dio_bank_cap[i].rising_edge_trigger_cap; + TrBuff[TrLength++] = cib_info->dio_bank_cap[i].falling_edge_trigger_cap; + + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_mask &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_mask &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_mask &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_mask &0x000000ff )); + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_shift_bits &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_shift_bits &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_shift_bits &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((cib_info->dio_bank_cap[i].io_shift_bits &0x000000ff )); + TrBuff[TrLength++] = (unsigned char )((BankDirection &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((BankDirection &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((BankDirection &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((BankDirection &0x000000ff )); + } + } + + *translateLength = TrLength; +} + + +static void get_bank_state (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankState =0 ; +unsigned int InputReg =0 ; +unsigned int OutputReg =0 ; + + +do + { +if (pRxHeader->Length !=1 ) + { + nStatus =SDCDIO_LENGTH_INVALID ; +break ; + } + BankIndex = (unsigned char )*(RxBuff +sizeof (DIO_HEADER ) +0 ); + +if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus =SDCDIO_BANK_NOT_FOUND ; +break ; + } + + +if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is individual input/output + InputReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,0 ); +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL (input), 1, InputReg:x%08x\n", dio_chl->info.line, InputReg); + InputReg &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL (input), 2, InputReg:x%08x\n", dio_chl->info.line, InputReg); + InputReg &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL (input), 3, InputReg:x%08x\n", dio_chl->info.line, InputReg); + + OutputReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,11 ); +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL (output), 4, OutputReg:x%08x\n", dio_chl->info.line, OutputReg); + OutputReg &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL (output), 5, OutputReg:x%08x\n", dio_chl->info.line, OutputReg); + OutputReg &= dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL (output), 6, OutputReg:x%08x\n", dio_chl->info.line, OutputReg); + + BankState = (InputReg | OutputReg) & cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL, 7, BankState:x%08x\n", dio_chl->info.line, BankState); + BankState = BankState >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank state, INDIVIDUAL, 8, BankState:x%08x\n", dio_chl->info.line, BankState); + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x00 )) + { +// bank is whole input + InputReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,0 ); +//printk("SUNIX: DIO (%d), get bank state, WHOLE (input), 1, InputReg:x%08x\n", dio_chl->info.line, InputReg); + BankState = InputReg & cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank state, WHOLE (input), 2, BankState:x%08x\n", dio_chl->info.line, BankState); + BankState = BankState >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank state, WHOLE (input), 3, BankState:x%08x\n", dio_chl->info.line, BankState); + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x00 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is whole output + OutputReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,11 ); +//printk("SUNIX: DIO (%d), get bank state, WHOLE (output), 1, OutputReg:x%08x\n", dio_chl->info.line, OutputReg); + BankState = OutputReg & cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank state, WHOLE (output), 2, BankState:x%08x\n", dio_chl->info.line, BankState); + BankState = BankState >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank state, WHOLE (output), 3, BankState:x%08x\n", dio_chl->info.line, BankState); + } +else + { + nStatus =SDCDIO_UNDEFINE_ERROR ; +break ; + } + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?5 :1 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { + TrBuff[TrLength++] = BankIndex; + TrBuff[TrLength++] = (unsigned char )((BankState &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((BankState &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((BankState &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((BankState &0x000000ff )); + } +else + { + TrBuff[TrLength++] = BankIndex; + } + + *translateLength = TrLength; +} + + +static void get_bank_input_delta_state (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankDeltaState =0 ; +unsigned int InputDeltaReg =0 ; + + +do + { +if (pRxHeader->Length !=1 ) + { + nStatus =SDCDIO_LENGTH_INVALID ; +break ; + } + BankIndex = (unsigned char )*(RxBuff +sizeof (DIO_HEADER ) +0 ); + +if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus =SDCDIO_BANK_NOT_FOUND ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].support_inputs !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_INPUT_CAP ; +break ; + } + + +if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is individual input/output +if ((~dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[BankIndex].io_mask) ==0x00000000 ) + { +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, no input\n", dio_chl->info.line); + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } + + InputDeltaReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,1 ); +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 1, InputDeltaReg:x%08x\n", dio_chl->info.line, InputDeltaReg); + InputDeltaReg &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 2, InputDeltaReg:x%08x\n", dio_chl->info.line, InputDeltaReg); + InputDeltaReg &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 3, InputDeltaReg:x%08x\n", dio_chl->info.line, InputDeltaReg); + BankDeltaState = InputDeltaReg >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input delta state, INDIVIDUAL, 4, BankDeltaState:x%08x\n", dio_chl->info.line, BankDeltaState); + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x00 )) + { +// bank is whole input + InputDeltaReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,1 ); +//printk("SUNIX: DIO (%d), get bank input delta state, WHOLE (input), 1, InputDeltaReg:x%08x\n", dio_chl->info.line, InputDeltaReg); + BankDeltaState = InputDeltaReg & cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input delta state, WHOLE (input), 2, BankDeltaState:x%08x\n", dio_chl->info.line, BankDeltaState); + BankDeltaState = BankDeltaState >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input delta state, WHOLE (input), 3, BankDeltaState:x%08x\n", dio_chl->info.line, BankDeltaState); + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x00 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is whole output + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } +else + { + nStatus =SDCDIO_UNDEFINE_ERROR ; +break ; + } + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?5 :1 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { + TrBuff[TrLength++] = BankIndex; + TrBuff[TrLength++] = (unsigned char )((BankDeltaState &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((BankDeltaState &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((BankDeltaState &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((BankDeltaState &0x000000ff )); + } +else + { + TrBuff[TrLength++] = BankIndex; + } + + *translateLength = TrLength; +} + + +static void get_bank_input_invert_enable (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankInputInvertEnable =0 ; +unsigned int InputInvertEnableReg =0 ; + + +do + { +if (pRxHeader->Length !=1 ) + { + nStatus =SDCDIO_LENGTH_INVALID ; +break ; + } + BankIndex = (unsigned char )*(RxBuff +sizeof (DIO_HEADER ) +0 ); + +if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus =SDCDIO_BANK_NOT_FOUND ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].support_inputs !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_INPUT_CAP ; +break ; + } + + +if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is individual input/output +if ((~dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[BankIndex].io_mask) ==0x00000000 ) + { +//printk("SUNIX: DIO (%d), get bank input inver enable, INDIVIDUAL, no input\n", dio_chl->info.line); + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } + + InputInvertEnableReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,2 ); + BankInputInvertEnable = InputInvertEnableReg; +//printk("SUNIX: DIO (%d), get bank input inver enable, INDIVIDUAL, 1, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + BankInputInvertEnable &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input inver enable, INDIVIDUAL, 2, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + BankInputInvertEnable &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), get bank input inver enable, INDIVIDUAL, 3, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + BankInputInvertEnable = BankInputInvertEnable >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input inver enable, INDIVIDUAL, 4, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + + dio_chl->InputInvertEnableReg = InputInvertEnableReg; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x00 )) + { +// bank is whole input + InputInvertEnableReg =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,2 ); + BankInputInvertEnable = InputInvertEnableReg; +//printk("SUNIX: DIO (%d), get bank input inver enable, WHOLE (input), 1, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + BankInputInvertEnable &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input inver enable, WHOLE (input), 2, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + BankInputInvertEnable = BankInputInvertEnable >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input inver enable, WHOLE (input), 3, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + + dio_chl->InputInvertEnableReg = InputInvertEnableReg; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x00 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is whole output + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } +else + { + nStatus =SDCDIO_UNDEFINE_ERROR ; +break ; + } + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?5 :1 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { + TrBuff[TrLength++] = BankIndex; + TrBuff[TrLength++] = (unsigned char )((BankInputInvertEnable &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((BankInputInvertEnable &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((BankInputInvertEnable &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((BankInputInvertEnable &0x000000ff )); + } +else + { + TrBuff[TrLength++] = BankIndex; + } + + *translateLength = TrLength; +} + + +static void set_bank_input_invert_enable (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankInputInvertEnable =0 ; +unsigned int InputInvertEnableRegByBank =0 ; +unsigned int InputInvertEnableReg =0 ; + + +do + { +if (pRxHeader->Length !=5 ) + { + nStatus =SDCDIO_LENGTH_INVALID ; +break ; + } + BankIndex = (unsigned char )*(RxBuff +sizeof (DIO_HEADER ) +0 ); + BankInputInvertEnable = (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +1 ) <<24 ); + BankInputInvertEnable |= (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +2 ) <<16 ); + BankInputInvertEnable |= (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +3 ) <<8 ); + BankInputInvertEnable |= (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +4 )); +//printk("SUNIX: DIO (%d), set bank input inver enable, BankIndex:x%02x, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankIndex, BankInputInvertEnable); +if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus =SDCDIO_BANK_NOT_FOUND ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].support_inputs !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_INPUT_CAP ; +break ; + } + + +if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is individual input/output +if ((~dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[BankIndex].io_mask) ==0x00000000 ) + { +//printk("SUNIX: DIO (%d), set bank input inver enable, INDIVIDUAL, no input\n", dio_chl->info.line); + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } + + BankInputInvertEnable &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), set bank input inver enable, INDIVIDUAL, 1, BankInputInvertEnable:x%08x\n", dio_chl->info.line, BankInputInvertEnable); + InputInvertEnableRegByBank = BankInputInvertEnable << cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), set bank input inver enable, INDIVIDUAL, 2, InputInvertEnableRegByBank:x%08x\n", dio_chl->info.line, InputInvertEnableRegByBank); + InputInvertEnableRegByBank &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), set bank input inver enable, INDIVIDUAL, 3, InputInvertEnableRegByBank:x%08x\n", dio_chl->info.line, InputInvertEnableRegByBank); + InputInvertEnableReg = dio_chl->InputInvertEnableReg & ~cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), set bank input inver enable, INDIVIDUAL, 4, InputInvertEnableReg:x%08x\n", dio_chl->info.line, InputInvertEnableReg); + InputInvertEnableReg |= InputInvertEnableRegByBank; +//printk("SUNIX: DIO (%d), set bank input inver enable, INDIVIDUAL, 5, InputInvertEnableReg:x%08x\n", dio_chl->info.line, InputInvertEnableReg); + +mem_tx32 (dio_chl->info.membase, dio_chl->info.memoffset,2 , InputInvertEnableReg); + dio_chl->InputInvertEnableReg = InputInvertEnableReg; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x00 )) + { +// bank is whole input + InputInvertEnableRegByBank = BankInputInvertEnable << cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), set bank input inver enable, WHOLE (input), 1, InputInvertEnableRegByBank:x%08x\n", dio_chl->info.line, InputInvertEnableRegByBank); + InputInvertEnableRegByBank &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), set bank input inver enable, WHOLE (input), 2, InputInvertEnableRegByBank:x%08x\n", dio_chl->info.line, InputInvertEnableRegByBank); + InputInvertEnableReg = dio_chl->InputInvertEnableReg & ~cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), set bank input inver enable, WHOLE (input), 3, InputInvertEnableReg:x%08x\n", dio_chl->info.line, InputInvertEnableReg); + InputInvertEnableReg |= InputInvertEnableRegByBank; +//printk("SUNIX: DIO (%d), set bank input inver enable, WHOLE (input), 4, InputInvertEnableReg:x%08x\n", dio_chl->info.line, InputInvertEnableReg); + +mem_tx32 (dio_chl->info.membase, dio_chl->info.memoffset,2 , InputInvertEnableReg); + dio_chl->InputInvertEnableReg = InputInvertEnableReg; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x00 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is whole output + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } +else + { + nStatus =SDCDIO_UNDEFINE_ERROR ; +break ; + } + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?1 :1 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { + TrBuff[TrLength++] = BankIndex; + } +else + { + TrBuff[TrLength++] = BankIndex; + } + + *translateLength = TrLength; +} + + +static void get_bank_input_latch_rising_edge (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankInputLatch =0 ; +unsigned int InputLatchRegPositiveEdgeR =0 ; + + +do + { +if (pRxHeader->Length !=1 ) + { + nStatus =SDCDIO_LENGTH_INVALID ; +break ; + } + BankIndex = (unsigned char )*(RxBuff +sizeof (DIO_HEADER ) +0 ); + +if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus =SDCDIO_BANK_NOT_FOUND ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].support_inputs !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_INPUT_CAP ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].rising_edge_trigger_cap !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_RISING_EDGE_TRIGGER_CAP ; +break ; + } + + +if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is individual input/output +if ((~dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[BankIndex].io_mask) ==0x00000000 ) + { +//printk("SUNIX: DIO (%d), get bank input latch rising edge, INDIVIDUAL, no input\n", dio_chl->info.line); + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } + + InputLatchRegPositiveEdgeR =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,3 ); + BankInputLatch = InputLatchRegPositiveEdgeR; +//printk("SUNIX: DIO (%d), get bank input latch rising edge, INDIVIDUAL, 1, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input latch rising edge, INDIVIDUAL, 2, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), get bank input latch rising edge, INDIVIDUAL, 3, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch = BankInputLatch >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input latch rising edge, INDIVIDUAL, 4, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + + dio_chl->InputLatchRegPositiveEdgeR = InputLatchRegPositiveEdgeR; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x00 )) + { +// bank is whole input + InputLatchRegPositiveEdgeR =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,3 ); + BankInputLatch = InputLatchRegPositiveEdgeR; +//printk("SUNIX: DIO (%d), get bank input latch rising edge, WHOLE (input), 1, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input latch rising edge, WHOLE (input), 2, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch = BankInputLatch >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input latch rising edge, WHOLE (input), 3, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + + dio_chl->InputLatchRegPositiveEdgeR = InputLatchRegPositiveEdgeR; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x00 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is whole output + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } +else + { + nStatus =SDCDIO_UNDEFINE_ERROR ; +break ; + } + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?5 :1 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { + TrBuff[TrLength++] = BankIndex; + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0x000000ff )); + } +else + { + TrBuff[TrLength++] = BankIndex; + } + + *translateLength = TrLength; +} + + +static void set_bank_input_latch_rising_edge (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankInputLatch =0 ; +unsigned int InputLatchRegPositiveEdgeW =0 ; + + +do + { +if (pRxHeader->Length !=5 ) + { + nStatus =SDCDIO_LENGTH_INVALID ; +break ; + } + BankIndex = (unsigned char )*(RxBuff +sizeof (DIO_HEADER ) +0 ); + BankInputLatch = (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +1 ) <<24 ); + BankInputLatch |= (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +2 ) <<16 ); + BankInputLatch |= (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +3 ) <<8 ); + BankInputLatch |= (unsigned int )(*(RxBuff +sizeof (DIO_HEADER ) +4 )); +//printk("SUNIX: DIO (%d), set bank input latch rising edge, BankIndex:x%02x, BankInputLatch:x%08x\n", dio_chl->info.line, BankIndex, BankInputLatch); +if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus =SDCDIO_BANK_NOT_FOUND ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].support_inputs !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_INPUT_CAP ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].rising_edge_trigger_cap !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_RISING_EDGE_TRIGGER_CAP ; +break ; + } + + +if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is individual input/output +if ((~dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[BankIndex].io_mask) ==0x00000000 ) + { +//printk("SUNIX: DIO (%d), set bank input latch rising edge, INDIVIDUAL, no input\n", dio_chl->info.line); + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } + + InputLatchRegPositiveEdgeW = BankInputLatch << cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), set bank input latch rising edge, INDIVIDUAL, 1, InputLatchRegPositiveEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegPositiveEdgeW); + InputLatchRegPositiveEdgeW &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), set bank input latch rising edge, INDIVIDUAL, 2, InputLatchRegPositiveEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegPositiveEdgeW); + InputLatchRegPositiveEdgeW &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), set bank input latch rising edge, INDIVIDUAL, 3, InputLatchRegPositiveEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegPositiveEdgeW); + InputLatchRegPositiveEdgeW |= (dio_chl->InputLatchRegPositiveEdgeW & ~cib_info->dio_bank_cap[BankIndex].io_mask); +//printk("SUNIX: DIO (%d), set bank input latch rising edge, INDIVIDUAL, 4, InputLatchRegPositiveEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegPositiveEdgeW); + +mem_tx32 (dio_chl->info.membase, dio_chl->info.memoffset,3 , InputLatchRegPositiveEdgeW); + dio_chl->InputLatchRegPositiveEdgeW = InputLatchRegPositiveEdgeW; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x00 )) + { +// bank is whole input + InputLatchRegPositiveEdgeW = BankInputLatch << cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), set bank input latch rising edge, WHOLE (input), 1, InputLatchRegPositiveEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegPositiveEdgeW); + InputLatchRegPositiveEdgeW &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), set bank input latch rising edge, WHOLE (input), 2, InputLatchRegPositiveEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegPositiveEdgeW); + InputLatchRegPositiveEdgeW |= (dio_chl->InputLatchRegPositiveEdgeW & ~cib_info->dio_bank_cap[BankIndex].io_mask); +//printk("SUNIX: DIO (%d), set bank input latch rising edge, WHOLE (input), 3, InputLatchRegPositiveEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegPositiveEdgeW); + +mem_tx32 (dio_chl->info.membase, dio_chl->info.memoffset,3 , InputLatchRegPositiveEdgeW); + dio_chl->InputLatchRegPositiveEdgeW = InputLatchRegPositiveEdgeW; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x00 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is whole output + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } +else + { + nStatus =SDCDIO_UNDEFINE_ERROR ; +break ; + } + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?1 :1 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { + TrBuff[TrLength++] = BankIndex; + } +else + { + TrBuff[TrLength++] = BankIndex; + } + + *translateLength = TrLength; +} + + +static void get_bank_input_latch_falling_edge (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankInputLatch =0 ; +unsigned int InputLatchRegNegativeEdgeR =0 ; + + +do + { +if (pRxHeader->Length !=1 ) + { + nStatus =SDCDIO_LENGTH_INVALID ; +break ; + } + BankIndex = (unsigned char )*(RxBuff +sizeof (DIO_HEADER ) +0 ); + +if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus =SDCDIO_BANK_NOT_FOUND ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].support_inputs !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_INPUT_CAP ; +break ; + } + +if (cib_info->dio_bank_cap[BankIndex].falling_edge_trigger_cap !=0x01 ) + { + nStatus =SDCDIO_UNSUPPORT_FALLING_EDGE_TRIGGER_CAP ; +break ; + } + + +if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is individual input/output +if ((~dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[BankIndex].io_mask) ==0x00000000 ) + { +//printk("SUNIX: DIO (%d), get bank input latch falling edge, INDIVIDUAL, no input\n", dio_chl->info.line); + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } + + InputLatchRegNegativeEdgeR =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,4 ); + BankInputLatch = InputLatchRegNegativeEdgeR; +//printk("SUNIX: DIO (%d), get bank input latch falling edge, INDIVIDUAL, 1, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input latch falling edge, INDIVIDUAL, 2, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch &= ~dio_chl->DirectionCtrlReg; +//printk("SUNIX: DIO (%d), get bank input latch falling edge, INDIVIDUAL, 3, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch = BankInputLatch >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input latch falling edge, INDIVIDUAL, 4, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + + dio_chl->InputLatchRegNegativeEdgeR = InputLatchRegNegativeEdgeR; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x01 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x00 )) + { +// bank is whole input + InputLatchRegNegativeEdgeR =mem_rx32 (dio_chl->info.membase, dio_chl->info.memoffset,4 ); + BankInputLatch = InputLatchRegNegativeEdgeR; +//printk("SUNIX: DIO (%d), get bank input latch falling edge, WHOLE (input), 1, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch &= cib_info->dio_bank_cap[BankIndex].io_mask; +//printk("SUNIX: DIO (%d), get bank input latch falling edge, WHOLE (input), 2, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + BankInputLatch = BankInputLatch >> cib_info->dio_bank_cap[BankIndex].io_shift_bits; +//printk("SUNIX: DIO (%d), get bank input latch falling edge, WHOLE (input), 3, BankInputLatch:x%08x\n", dio_chl->info.line, BankInputLatch); + + dio_chl->InputLatchRegNegativeEdgeR = InputLatchRegNegativeEdgeR; + } +else if ((cib_info->dio_bank_cap[BankIndex].support_inputs ==0x00 ) && (cib_info->dio_bank_cap[BankIndex].support_outputs ==0x01 )) + { +// bank is whole output + nStatus =SDCDIO_NO_INPUT_IO ; +break ; + } +else + { + nStatus =SDCDIO_UNDEFINE_ERROR ; +break ; + } + + }while (false); + +memset (TrBuff,0 ,SUNIX_SDC_DIO_BUFF ); + TrLength =0 ; + + pTrHeader->Version =0x01 ; + pTrHeader->CmdResponseEventData = pRxHeader->CmdResponseEventData |0x8000 ; + pTrHeader->ResponseStatus = nStatus; + pTrHeader->Length = (nStatus ==SDCDIO_STATUS_SUCCESS )?5 :1 ; + TrLength =sizeof (DIO_HEADER ); +if (pTrHeader->ResponseStatus ==SDCDIO_STATUS_SUCCESS ) + { + TrBuff[TrLength++] = BankIndex; + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0xff000000 ) >>24 ); + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0x00ff0000 ) >>16 ); + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0x0000ff00 ) >>8 ); + TrBuff[TrLength++] = (unsigned char )((BankInputLatch &0x000000ff )); + } +else + { + TrBuff[TrLength++] = BankIndex; + } + + *translateLength = TrLength; +} + + +static void set_bank_input_latch_falling_edge (struct sunix_sdc_dio_channel *dio_chl,unsigned int incomeLength,unsigned int * translateLength) +{ +struct sdc_cib * cib_info = &dio_chl->info.cib_info; +PDIO_HEADER pRxHeader = (PDIO_HEADER )dio_chl->incomeBuff; +unsigned char * RxBuff = dio_chl->incomeBuff; +PDIO_HEADER pTrHeader = (PDIO_HEADER )dio_chl->translateBuff; +unsigned char * TrBuff = dio_chl->translateBuff; +unsigned int nStatus =SDCDIO_STATUS_SUCCESS ; +unsigned int TrLength =0 ; +unsigned char BankIndex =0 ; +unsigned int BankInputLatch =0 ; +unsigned int InputLatchRegNegativeEdgeW =0 ; + + + do + { + if (pRxHeader->Length != 5) + { + nStatus = SDCDIO_LENGTH_INVALID; + break; + } + BankIndex = (unsigned char)*(RxBuff + sizeof(DIO_HEADER) + 0); + BankInputLatch = (unsigned int)(*(RxBuff + sizeof(DIO_HEADER) + 1) << 24); + BankInputLatch |= (unsigned int)(*(RxBuff + sizeof(DIO_HEADER) + 2) << 16); + BankInputLatch |= (unsigned int)(*(RxBuff + sizeof(DIO_HEADER) + 3) << 8); + BankInputLatch |= (unsigned int)(*(RxBuff + sizeof(DIO_HEADER) + 4)); + //printk("SUNIX: DIO (%d), set bank input latch falling edge, BankIndex:x%02x, BankInputLatch:x%08x\n", dio_chl->info.line, BankIndex, BankInputLatch); + if (!(BankIndex < cib_info->dio_number_of_banks)) + { + nStatus = SDCDIO_BANK_NOT_FOUND; + break; + } + + if (cib_info->dio_bank_cap[BankIndex].support_inputs != 0x01) + { + nStatus = SDCDIO_UNSUPPORT_INPUT_CAP; + break; + } + + if (cib_info->dio_bank_cap[BankIndex].falling_edge_trigger_cap != 0x01) + { + nStatus = SDCDIO_UNSUPPORT_FALLING_EDGE_TRIGGER_CAP; + break; + } + + + if ((cib_info->dio_bank_cap[BankIndex].support_inputs == 0x01) && (cib_info->dio_bank_cap[BankIndex].support_outputs == 0x01)) + { + // bank is individual input/output + if ((~dio_chl->DirectionCtrlReg & cib_info->dio_bank_cap[BankIndex].io_mask) == 0x00000000) + { + //printk("SUNIX: DIO (%d), set bank input latch falling edge, INDIVIDUAL, no input\n", dio_chl->info.line); + nStatus = SDCDIO_NO_INPUT_IO; + break; + } + + InputLatchRegNegativeEdgeW = BankInputLatch << cib_info->dio_bank_cap[BankIndex].io_shift_bits; + //printk("SUNIX: DIO (%d), set bank input latch falling edge, INDIVIDUAL, 1, InputLatchRegNegativeEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegNegativeEdgeW); + InputLatchRegNegativeEdgeW &= cib_info->dio_bank_cap[BankIndex].io_mask; + //printk("SUNIX: DIO (%d), set bank input latch falling edge, INDIVIDUAL, 2, InputLatchRegNegativeEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegNegativeEdgeW); + InputLatchRegNegativeEdgeW &= ~dio_chl->DirectionCtrlReg; + //printk("SUNIX: DIO (%d), set bank input latch falling edge, INDIVIDUAL, 3, InputLatchRegNegativeEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegNegativeEdgeW); + InputLatchRegNegativeEdgeW |= (dio_chl->InputLatchRegNegativeEdgeW & ~cib_info->dio_bank_cap[BankIndex].io_mask); + //printk("SUNIX: DIO (%d), set bank input latch falling edge, INDIVIDUAL, 4, InputLatchRegNegativeEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegNegativeEdgeW); + + mem_tx32(dio_chl->info.membase, dio_chl->info.memoffset, 4, InputLatchRegNegativeEdgeW); + dio_chl->InputLatchRegNegativeEdgeW = InputLatchRegNegativeEdgeW; + } + else if ((cib_info->dio_bank_cap[BankIndex].support_inputs == 0x01) && (cib_info->dio_bank_cap[BankIndex].support_outputs == 0x00)) + { + // bank is whole input + InputLatchRegNegativeEdgeW = BankInputLatch << cib_info->dio_bank_cap[BankIndex].io_shift_bits; + //printk("SUNIX: DIO (%d), set bank input latch falling edge, WHOLE (input), 1, InputLatchRegNegativeEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegNegativeEdgeW); + InputLatchRegNegativeEdgeW &= cib_info->dio_bank_cap[BankIndex].io_mask; + //printk("SUNIX: DIO (%d), set bank input latch falling edge, WHOLE (input), 2, InputLatchRegNegativeEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegNegativeEdgeW); + InputLatchRegNegativeEdgeW |= (dio_chl->InputLatchRegNegativeEdgeW & ~cib_info->dio_bank_cap[BankIndex].io_mask); + //printk("SUNIX: DIO (%d), set bank input latch falling edge, WHOLE (input), 3, InputLatchRegNegativeEdgeW:x%08x\n", dio_chl->info.line, InputLatchRegNegativeEdgeW); + + mem_tx32(dio_chl->info.membase, dio_chl->info.memoffset, 4, InputLatchRegNegativeEdgeW); + dio_chl->InputLatchRegNegativeEdgeW = InputLatchRegNegativeEdgeW; + } + else if ((cib_info->dio_bank_cap[BankIndex].support_inputs == 0x00) && (cib_info->dio_bank_cap[BankIndex].support_outputs == 0x01)) + { + // bank is whole output + nStatus = SDCDIO_NO_INPUT_IO; + break; + }Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
What is that for? We already have list functions the kernel.
drivers/mfd/sdc_define.h
Quoted 169 lines
drivers/mfd/list.c new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Split that off into separate drivers for gpio, spi, serial, etc., ...
drivers/mfd/spi.c
Quoted 815 lines
drivers/mfd/sdc_define.h new file +548
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
completely drop that proprietary device node, use spi subsystem.
drivers/mfd/uart.c
Quoted 5,207 lines
drivers/mfd/spi.c new file +375
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
NO! Don't write your own tty driver - use serial subsystem. And if the device is 8250 compatible, use that one.
drivers/mfd/uart.c
Quoted 480 lines
drivers/mfd/uart.c new file +480
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Summary:
Around 90% of your code is completely redundant, introducing completely incompatible device-specific userland api's (char devices), instead of using the corresponding subsystems (gpio, serial, spi, etc).
Major 2do's:
* remove all dead code (drop everything that's just for ancient kernel versions)
* use the corresponding subsystems for the subdevices, eg:
gpio for the dio sebdev
serial/8250 for the sdc subdev
spi fo the spi subdev
* move that code under the corresponding subsys trees, make the drivers standalone (eg. as platform devices) and let the mfd just handle the board specialties and instantiate the individual sub devices
* drop the useless printf()s
* use the pci subsystem for card probing (not manually scanning)
* drop the global arrays, use per-device privdata
If some of these subdevs really have some special functionality, that can't be handled by the corresponding subsystems yet, let us know.
And please read the documentation before writing that much code.
thx
--mtx
Signature · 8 lines
--- Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren GPG/PGP-Schlüssel zu. --- Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Part of the diff is not shown here. View the raw message.