spi: Add a utility pointer for the application on SPI callback
It might be needed sometime to get some private data forwarded to the callback, thus such user_data pointer is the easiest way to proceed. Adding a macro to set the word size as well. Change-Id: I68cbe2d480120253ccb13f13c656a38c27e21604 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
ded73a41b1
commit
524a50e61e
3 changed files with 15 additions and 6 deletions
|
@ -172,7 +172,7 @@ out:
|
|||
_spi_control_cs(dev, 0);
|
||||
|
||||
if (spi->callback) {
|
||||
spi->callback(dev, cb_type);
|
||||
spi->callback(dev, cb_type, spi->user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,8 @@ static void pull_data(struct device *dev)
|
|||
spi->t_len -= cnt;
|
||||
}
|
||||
|
||||
static int spi_intel_configure(struct device *dev, struct spi_config *config)
|
||||
static int spi_intel_configure(struct device *dev,
|
||||
struct spi_config *config, void *user_data)
|
||||
{
|
||||
struct spi_intel_config *info = dev->config->config_info;
|
||||
struct spi_intel_data *spi = dev->driver_data;
|
||||
|
@ -288,6 +289,7 @@ static int spi_intel_configure(struct device *dev, struct spi_config *config)
|
|||
spi->tx_buf = spi->rx_buf = NULL;
|
||||
spi->tx_buf_len = spi->rx_buf_len = spi->t_len = 0;
|
||||
spi->callback = config->callback;
|
||||
spi->user_data = user_data;
|
||||
|
||||
return DEV_OK;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ struct spi_intel_data {
|
|||
uint32_t sscr0;
|
||||
uint32_t sscr1;
|
||||
spi_callback callback;
|
||||
void *user_data;
|
||||
uint8_t *tx_buf;
|
||||
uint32_t tx_buf_len;
|
||||
uint8_t *rx_buf;
|
||||
|
|
|
@ -57,6 +57,7 @@ extern "C" {
|
|||
|
||||
#define SPI_WORD_SIZE_MASK (0xFF << 3)
|
||||
#define SPI_WORD_SIZE_GET(_in_) ((_in_ & SPI_WORD_SIZE_MASK) >> 3)
|
||||
#define SPI_WORD_SIZE(_in_) (_in_ << 3)
|
||||
|
||||
enum spi_cb_type {
|
||||
SPI_CB_WRITE = 1,
|
||||
|
@ -66,7 +67,8 @@ enum spi_cb_type {
|
|||
};
|
||||
|
||||
/* application callback function signature */
|
||||
typedef void (*spi_callback)(struct device *dev, enum spi_cb_type cb_type);
|
||||
typedef void (*spi_callback)(struct device *dev,
|
||||
enum spi_cb_type cb_type, void *user_data);
|
||||
|
||||
/*
|
||||
* config is a bit field with the following parts:
|
||||
|
@ -85,7 +87,8 @@ struct spi_config {
|
|||
spi_callback callback;
|
||||
};
|
||||
|
||||
typedef int (*spi_api_configure)(struct device *dev, struct spi_config *config);
|
||||
typedef int (*spi_api_configure)(struct device *dev,
|
||||
struct spi_config *config, void *user_data);
|
||||
typedef int (*spi_api_slave_select)(struct device *dev, uint32_t slave);
|
||||
typedef int (*spi_api_io)(struct device *dev,
|
||||
uint8_t *tx_buf, uint32_t tx_buf_len,
|
||||
|
@ -104,13 +107,16 @@ struct spi_driver_api {
|
|||
* @brief Configure a host controller for operating against slaves
|
||||
* @param dev Pointer to the device structure for the driver instance
|
||||
* @param config Pointer to the application provided configuration
|
||||
* @param user_data Pointer to some user application memory which will
|
||||
* be forwarded via the callback.
|
||||
*
|
||||
* @return DEV_OK if successful, another DEV_* code otherwise.
|
||||
*/
|
||||
static inline int spi_configure(struct device *dev, struct spi_config *config)
|
||||
static inline int spi_configure(struct device *dev,
|
||||
struct spi_config *config, void *user_data)
|
||||
{
|
||||
struct spi_driver_api *api = (struct spi_driver_api *)dev->driver_api;
|
||||
return api->configure(dev, config);
|
||||
return api->configure(dev, config, user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue