BOOL AT91_SPI_Driver::nWrite16_nRead16(const SPI_CONFIGURATION &Configuration, UINT16 *Write16, INT32 WriteCount, UINT16 *Read16, INT32 ReadCount, INT32 ReadStartOffset) { NATIVE_PROFILE_HAL_PROCESSOR_SPI(); GLOBAL_LOCK(irq); SPI_DEBUG_PRINT(" spi write 16 \r\n"); if(g_AT91_SPI_Driver.m_Enabled[Configuration.SPI_mod]) { lcd_printf("\fSPI Xaction 1\r\n"); hal_printf("\fSPI Xaction 1\r\n"); HARD_BREAKPOINT(); return FALSE; } if(Configuration.SPI_mod > AT91_SPI::c_MAX_SPI) { lcd_printf("\fSPI wrong mod\r\n"); hal_printf("\fSPI wrong mod\r\n"); HARD_BREAKPOINT(); return FALSE; } if(!Xaction_Start(Configuration)) return FALSE; { SPI_XACTION_16 Transaction; Transaction.Read16 = Read16; Transaction.ReadCount = ReadCount; Transaction.ReadStartOffset = ReadStartOffset; Transaction.Write16 = Write16; Transaction.WriteCount = WriteCount; Transaction.SPI_mod = Configuration.SPI_mod; Transaction.BusyPin = Configuration.BusyPin; if(!Xaction_nWrite16_nRead16(Transaction)) return FALSE; } SPI_DEBUG_PRINT(" B4 xs 16 \r\n"); return Xaction_Stop(Configuration); }
/* * Function opens a tty device when called from user space */ static int ifx_spi_open(struct tty_struct *tty, struct file *filp) { int status = 0; //20100607, [email protected], add else code [START] struct ifx_spi_data *spi_data; if(gspi_data) { spi_data = gspi_data; spi_data->ifx_tty = tty; tty->driver_data = spi_data; ifx_spi_buffer_initialization(); spi_data->throttle = 0; SPI_DEBUG_PRINT("ifx_spi_open\n"); } else { ifx_spi_buffer_initialization(); SPI_DEBUG_PRINT("ifx_spi_open failed!!\n"); } //20100607, [email protected], add else code [END] return status; }
static int ifx_spi_write(struct tty_struct *tty, const unsigned char *buf, int count) { #if defined (CONFIG_MODEM_IFX) unsigned int u32register = 0 ; unsigned int value = 0; #endif struct ifx_spi_data *spi_data = (struct ifx_spi_data *)tty->driver_data; if(spi_data==NULL) { printk("ifx_spi_write failed : spi_data is null\n"); //syblue.lee 100604 return 0; } ifx_ret_count = 0; #if defined (CONFIG_MODEM_MDM) DUMP_SPI_BUFFER(__FUNCTION__, buf, count); #endif spi_data->ifx_tty = tty; spi_data->ifx_tty->low_latency = 1; if( !buf ){ printk("File: ifx_n721_spi.c\tFunction: int ifx_spi_write()\t Buffer NULL\n"); return ifx_ret_count; } if(!count){ printk("File: ifx_n721_spi.c\tFunction: int ifx_spi_write()\t Count is ZERO\n"); return ifx_ret_count; } ifx_master_initiated_transfer = 1; ifx_spi_buf = buf; ifx_spi_count = count; SPI_DEBUG_PRINT("ifx_spi_write\n"); ifx_spi_set_mrdy_signal(1); #if defined (CONFIG_MODEM_MDM) wait_for_completion(&spi_data->ifx_read_write_completion); #elif defined (CONFIG_MODEM_IFX) wait_for_completion_timeout(&spi_data->ifx_read_write_completion, 2*HZ); if(ifx_ret_count==0) { ifx_spi_set_mrdy_signal(0); u32register = readl(IO_ADDRESS(0x6000d1b8)); //lge_debug[D_SPI].enable = 1; printk("%s -u32register = %08X, SRDY = %d\n", __FUNCTION__, u32register, ((u32register>>5)&0x00000001)); }
BOOL AT91_SPI_Driver::nWrite8_nRead8(const SPI_CONFIGURATION &Configuration, UINT8 *Write8, INT32 WriteCount, UINT8 *Read8, INT32 ReadCount, INT32 ReadStartOffset) { NATIVE_PROFILE_HAL_PROCESSOR_SPI(); SPI_DEBUG_PRINT(" spi write 8 \r\n"); if(g_AT91_SPI_Driver.m_Enabled[Configuration.SPI_mod]) { lcd_printf("\fSPI Xaction 1\r\n"); HARD_BREAKPOINT(); return FALSE; } if(Configuration.SPI_mod > AT91_SPI::c_MAX_SPI) { lcd_printf("\fSPI wrong mod\r\n"); HARD_BREAKPOINT(); return FALSE; } if(!Xaction_Start(Configuration)) return FALSE; { SPI_XACTION_8 Transaction; Transaction.Read8 = Read8; Transaction.ReadCount = ReadCount; Transaction.ReadStartOffset = ReadStartOffset; Transaction.Write8 = Write8; Transaction.WriteCount = WriteCount; Transaction.SPI_mod = Configuration.SPI_mod; Transaction.BusyPin = Configuration.BusyPin; if(!Xaction_nWrite8_nRead8(Transaction)) return FALSE; } return Xaction_Stop(Configuration); }
BOOL MC9328MXL_SPI_Driver::Xaction_nWrite16_nRead16( SPI_XACTION_16& Transaction ) { NATIVE_PROFILE_HAL_PROCESSOR_SPI(); UINT16 Data16; if(!g_MC9328MXL_SPI_Driver.m_Enabled[ Transaction.SPI_mod ]) { hal_printf("\fSPI Xaction OFF\r\n"); lcd_printf("\fSPI Xaction OFF\r\n"); ASSERT(FALSE); return FALSE; } SPI_DEBUG_PRINT("\fxwr16\r\n"); MC9328MXL_SPI& SPI = MC9328MXL::SPI( Transaction.SPI_mod ); UINT16* Write16 = Transaction.Write16; INT32 WriteCount = Transaction.WriteCount; UINT16* Read16 = Transaction.Read16; INT32 ReadCount = Transaction.ReadCount; INT32 ReadStartOffset = Transaction.ReadStartOffset; INT32 ReadTotal = 0; // as master, we must always write something before reading or not if(WriteCount <= 0) { ASSERT(FALSE); return FALSE; } if(Write16 == NULL) { ASSERT(FALSE); return FALSE; } if((ReadCount > 0) && (Read16 == NULL)) { ASSERT(FALSE); return FALSE; } if(ReadCount) { ReadTotal = ReadCount + ReadStartOffset; // we need to read as many bytes as the buffer is long, plus the offset at which we start } INT32 loopCnt= ReadTotal; // take the max of Read+offset or WrCnt if (loopCnt < WriteCount) loopCnt = WriteCount; // we will use WriteCount to move in the Write16 array // so we do no want to go past the end when we will check for // WriteCount to be bigger than zero WriteCount -= 1; while(loopCnt--) { SPI.TXDATAREG = Write16[0]; SPI.CONTROLREG |= SPI.CONTROLREG_XCH; // wait while the transmit buffer is full and receive buffer is empty while(!SPI.TransmitBufferEmpty() || !SPI.ShiftBufferEmpty()|| SPI.ReceiveBufferEmpty()); Data16 = SPI.RXDATAREG; // repeat last write word for all subsequent reads if(WriteCount) { WriteCount--; Write16++; } // only save data once we have reached ReadCount-1 portion of words ReadTotal--; if((ReadTotal>=0) && (ReadTotal < ReadCount)) { Read16[0] = Data16; Read16++; } } return TRUE; }