driver/spi: call bind and unbind when user open or close to save power

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-09-18 11:01:33 +08:00 committed by Petro Karashchenko
parent 76dfffe834
commit 93b2a3744f

View file

@ -195,6 +195,13 @@ static int spi_slave_open(FAR struct file *filep)
/* Increment the count of open references on the driver */
if (priv->crefs == 0)
{
SPIS_CTRLR_BIND(priv->ctrlr, (FAR struct spi_slave_dev_s *)priv,
CONFIG_SPI_SLAVE_DRIVER_MODE,
CONFIG_SPI_SLAVE_DRIVER_WIDTH);
}
priv->crefs++;
DEBUGASSERT(priv->crefs > 0);
@ -246,6 +253,11 @@ static int spi_slave_close(FAR struct file *filep)
DEBUGASSERT(priv->crefs > 0);
priv->crefs--;
if (priv->crefs == 0)
{
SPIS_CTRLR_UNBIND(priv->ctrlr);
}
/* If the count has decremented to zero and the driver has been already
* unlinked, then dispose of the driver resources.
*/
@ -529,6 +541,7 @@ static int spi_slave_unlink(FAR struct inode *inode)
if (priv->crefs <= 0)
{
SPIS_CTRLR_UNBIND(priv->ctrlr);
nxmutex_destroy(&priv->lock);
kmm_free(priv);
inode->i_private = NULL;
@ -798,10 +811,6 @@ int spi_slave_register(FAR struct spi_slave_ctrlr_s *ctrlr, int bus)
kmm_free(priv);
}
SPIS_CTRLR_BIND(priv->ctrlr, (FAR struct spi_slave_dev_s *)priv,
CONFIG_SPI_SLAVE_DRIVER_MODE,
CONFIG_SPI_SLAVE_DRIVER_WIDTH);
spiinfo("SPI Slave driver loaded successfully!\n");
return ret;