I2C driver should support the RESET method as well

This commit is contained in:
Gregory Nutt 2016-02-03 07:32:25 -06:00
parent be3e86ec89
commit 8fa9b99e7c
2 changed files with 71 additions and 32 deletions

View File

@ -249,17 +249,13 @@ static ssize_t i2cdrvr_write(FAR struct file *filep, FAR const char *buffer,
static int i2cdrvr_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
i2cvdbg("cmd=%d arg=%lu\n", cmd, arg);
/* Only one command is supported */
if (cmd == I2CIOC_TRANSFER)
{
FAR struct inode *inode = filep->f_inode;
FAR struct i2c_driver_s *priv;
FAR struct i2c_transfer_s *transfer;
int ret;
i2cvdbg("cmd=%d arg=%lu\n", cmd, arg);
/* Get our private data structure */
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
@ -268,11 +264,6 @@ static int i2cdrvr_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
priv = (FAR struct i2c_driver_s *)inode->i_private;
DEBUGASSERT(priv);
/* Get the reference to the i2c_transfer_s structure */
transfer = (FAR struct i2c_transfer_s *)((uintptr_t)arg);
DEBUGASSERT(transfer != NULL);
/* Get exclusive access to the I2C driver state structure */
ret = sem_wait(&priv->exclsem);
@ -283,17 +274,51 @@ static int i2cdrvr_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
return -errcode;
}
/* Process the IOCTL command */
switch (cmd)
{
/* Command: I2CIOC_TRANSFER
* Description: Perform an I2C transfer
* Argument: A reference to an instance of struct i2c_transfer_s.
* Dependencies: CONFIG_I2C_DRIVER
*/
case I2CIOC_TRANSFER:
{
/* Get the reference to the i2c_transfer_s structure */
transfer = (FAR struct i2c_transfer_s *)((uintptr_t)arg);
DEBUGASSERT(transfer != NULL);
/* Perform the transfer */
ret = I2C_TRANSFER(priv->i2c, transfer->msgv, transfer->msgc);
}
break;
#ifdef CONFIG_I2C_RESET
/* Command: I2CIOC_RESET
* Description: Perform an I2C bus reset in an attempt to break loose
* stuck I2C devices.
* Argument: None
* Dependencies: CONFIG_I2C_DRIVER && CONFIG_I2C_RESET
*/
case I2CIOC_RESET:
{
ret = I2C_RESET(priv->i2c);
}
break;
#endif
default:
ret = -ENOTTY;
break;
}
sem_post(&priv->exclsem);
return ret;
}
else
{
return -ENOTTY;
}
}
/****************************************************************************

View File

@ -81,6 +81,11 @@
* (re-)start of transfer */
/* I2C Character Driver IOCTL Commands **************************************/
/* The I2C driver is intended to support application testing of the I2C bus.
* The I2C driver simply wraps an instance of struct i2c_dev_s and then
* provides the following IOCTL commands to access each method of the I2c
* interface.
*/
/* Command: I2CIOC_TRANSFER
* Description: Perform an I2C transfer
@ -90,6 +95,15 @@
#define I2CIOC_TRANSFER _I2CIOC(0x0001)
/* Command: I2CIOC_RESET
* Description: Perform an I2C bus reset in an attempt to break loose stuck
* I2C devices.
* Argument: None
* Dependencies: CONFIG_I2C_DRIVER && CONFIG_I2C_RESET
*/
#define I2CIOC_RESET _I2CIOC(0x0002)
/* Access macros ************************************************************/
/****************************************************************************