static int xspi_release(struct inode *inode, struct file *filp) { struct xspi_instance *dev = filp->private_data; func_enter(); if (down_interruptible(&dev->sem)) return -EINTR; if (--dev->use_count == 0) { /* This was the last closer: stop the device and free the IRQ */ if (wait_event_interruptible(dev->waitq, XSpi_Stop(&dev->Spi) != XST_DEVICE_BUSY) != 0) { /* Abort transfer by brute force */ XSpi_Abort(&dev->Spi); } disable_irq(dev->irq); free_irq(dev->irq, &dev->Spi); } up(&dev->sem); return 0; }
/***************************************************************************//** * @brief spi_init *******************************************************************************/ int32_t spi_init(uint32_t device_id, uint8_t clk_pha, uint8_t clk_pol) { uint32_t base_addr = 0; uint32_t spi_options = 0; #ifdef _XPARAMETERS_PS_H_ spi_config = XSpiPs_LookupConfig(device_id); base_addr = spi_config->BaseAddress; XSpiPs_CfgInitialize(&spi_instance, spi_config, base_addr); spi_options = XSPIPS_MASTER_OPTION | (clk_pol ? XSPIPS_CLK_ACTIVE_LOW_OPTION : 0) | (clk_pha ? XSPIPS_CLK_PHASE_1_OPTION : 0) | (spi_decoded_cs ? XSPIPS_DECODE_SSELECT_OPTION : 0) | XSPIPS_FORCE_SSELECT_OPTION; XSpiPs_SetOptions(&spi_instance, spi_options); XSpiPs_SetClkPrescaler(&spi_instance, XSPIPS_CLK_PRESCALE_32); /* FIXME: Temporary 15.2 Fix */ XSpiPs_CfgInitialize(&spi_instance, spi_config, base_addr); XSpiPs_SetOptions(&spi_instance, spi_options); XSpiPs_SetClkPrescaler(&spi_instance, XSPIPS_CLK_PRESCALE_32); #else XSpi_Initialize(&spi_instance, device_id); XSpi_Stop(&spi_instance); spi_config = XSpi_LookupConfig(device_id); base_addr = spi_config->BaseAddress; XSpi_CfgInitialize(&spi_instance, spi_config, base_addr); spi_options = XSP_MASTER_OPTION | (clk_pol ? XSP_CLK_ACTIVE_LOW_OPTION : 0) | (clk_pha ? XSP_CLK_PHASE_1_OPTION : 0) | XSP_MANUAL_SSELECT_OPTION; XSpi_SetOptions(&spi_instance, spi_options); XSpi_Start(&spi_instance); XSpi_IntrGlobalDisable(&spi_instance); #endif return 0; }
void OLED_HostTerm(PmodOLED *InstancePtr) { ///* Make the Data/Command select, Reset, and SPI CS pins be inputs. //*/ OLED_SetGPIOBits(InstancePtr, DataCmd | Reset, true); OLED_SetGPIOTristateBits(InstancePtr, DataCmd | Reset, true); ///* Make power control pins be inputs. The pullup resistors on the //** board will ensure that the power supplies stay off. //*/ OLED_SetGPIOBits(InstancePtr, VddCtrl | VbatCtrl, true); OLED_SetGPIOTristateBits(InstancePtr, VddCtrl | VbatCtrl, true); XSpi_Stop(&InstancePtr->OLEDSpi); }
/***************************************************************************//** * @brief spi_init *******************************************************************************/ int32_t spi_init(uint32_t device_id, uint8_t clk_pha, uint8_t clk_pol) { uint32_t base_addr = 0; uint32_t control_val = 0; #ifdef _XPARAMETERS_PS_H_ uint8_t byte = 0; spi_config = XSpiPs_LookupConfig(device_id); base_addr = spi_config->BaseAddress; XSpiPs_CfgInitialize(&spi_instance, spi_config, base_addr); control_val = XSPIPS_CR_SSFORCE_MASK | XSPIPS_CR_SSCTRL_MASK | 4 << XSPIPS_CR_PRESC_SHIFT | (clk_pha ? XSPIPS_CR_CPHA_MASK : 0) | (clk_pol ? XSPIPS_CR_CPOL_MASK : 0) | XSPIPS_CR_MSTREN_MASK; XSpiPs_WriteReg(base_addr, XSPIPS_CR_OFFSET, control_val); for(byte = 0; byte < 128; byte++) { XSpiPs_ReadReg(base_addr, XSPIPS_RXD_OFFSET); } #else XSpi_Initialize(&spi_instance, device_id); XSpi_Stop(&spi_instance); spi_config = XSpi_LookupConfig(device_id); base_addr = spi_config->BaseAddress; XSpi_CfgInitialize(&spi_instance, spi_config, base_addr); control_val = XSP_MASTER_OPTION | XSP_CLK_PHASE_1_OPTION | XSP_MANUAL_SSELECT_OPTION; XSpi_SetOptions(&spi_instance, control_val); XSpi_Start(&spi_instance); XSpi_IntrGlobalDisable(&spi_instance); XSpi_SetSlaveSelect(&spi_instance, 1); #endif return SUCCESS; }
/*** AD1_end(void) ** ** Parameters: ** InstancePtr - PmodAD1 object to stop ** ** Return Value: ** none ** ** Errors: ** none ** ** Description: ** Stops the device */ void AD1_end(PmodAD1* InstancePtr){ XSpi_Stop(&InstancePtr->AD1Spi); }
/*** DA1_end(void) ** ** Parameters: ** InstancePtr - PmodDA1 object to stop ** ** Return Value: ** none ** ** Errors: ** none ** ** Description: ** Stops the device */ void DA1_end(PmodDA1* InstancePtr){ XSpi_Stop(&InstancePtr->DA1Spi); }
/*** DPG1_end(void) ** ** Parameters: ** InstancePtr - PmodDPG1 object to stop ** ** Return Value: ** none ** ** Errors: ** none ** ** Description: ** Stops the device */ void DPG1_end(PmodDPG1* InstancePtr){ XSpi_Stop(&InstancePtr->DPG1Spi); }
/*** NAV_end(void) ** ** Parameters: ** InstancePtr - PmodNAV object to stop ** ** Return Value: ** none ** ** Errors: ** none ** ** Description: ** Stops the device */ void NAV_end(PmodNAV* InstancePtr){ XSpi_Stop(&InstancePtr->NAVSpi); }