i2c: simplify API and driver_api with generic transfer function

With the introduction of generic transfer function, it is no longer
needed to specify read or write functions explicitly in drivers.
All read/write functions can now thus call the generic transfer
function to achieve the same result.

With this change, the transfer function becomes mandatory, and
should always be available.

Change-Id: Ia6fb98e58b84330a56a5d44ed3df9db42c3a5e88
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2015-10-09 10:38:10 -07:00 committed by Anas Nashif
commit 1c96cdeb52
2 changed files with 7 additions and 50 deletions

View file

@ -716,27 +716,6 @@ static int i2c_dw_set_callback(struct device *dev, i2c_callback cb)
return DEV_OK; return DEV_OK;
} }
static int i2c_dw_write(struct device *dev, uint8_t *buf,
uint32_t len, uint16_t slave_addr)
{
return i2c_dw_transfer(dev, buf, len, 0, 0, slave_addr, 0);
}
static int i2c_dw_read(struct device *dev, uint8_t *buf,
uint32_t len, uint16_t slave_addr)
{
return i2c_dw_transfer(dev, 0, 0, buf, len, slave_addr, 0);
}
static int i2c_dw_polling_write(struct device *dev,
uint8_t *write_buf, uint32_t write_len,
uint16_t slave_address)
{
return i2c_dw_poll_transfer(dev, write_buf, write_len,
0, 0, slave_address, 0);
}
static int i2c_dw_suspend(struct device *dev) static int i2c_dw_suspend(struct device *dev)
{ {
DBG("I2C: suspend called - function not yet implemented\n"); DBG("I2C: suspend called - function not yet implemented\n");
@ -756,12 +735,9 @@ static int i2c_dw_resume(struct device *dev)
static struct i2c_driver_api funcs = { static struct i2c_driver_api funcs = {
.configure = i2c_dw_runtime_configure, .configure = i2c_dw_runtime_configure,
.set_callback = i2c_dw_set_callback, .set_callback = i2c_dw_set_callback,
.write = i2c_dw_write,
.read = i2c_dw_read,
.transfer = i2c_dw_transfer, .transfer = i2c_dw_transfer,
.suspend = i2c_dw_suspend, .suspend = i2c_dw_suspend,
.resume = i2c_dw_resume, .resume = i2c_dw_resume,
.polling_write = i2c_dw_polling_write,
.poll_transfer = i2c_dw_poll_transfer, .poll_transfer = i2c_dw_poll_transfer,
}; };

View file

@ -77,10 +77,6 @@ typedef int (*i2c_api_configure_t)(struct device *dev,
uint32_t dev_config); uint32_t dev_config);
typedef int (*i2c_api_set_callback_t)(struct device *dev, typedef int (*i2c_api_set_callback_t)(struct device *dev,
i2c_callback cb); i2c_callback cb);
typedef int (*i2c_api_io_t)(struct device *dev,
uint8_t *buf,
uint32_t len,
uint16_t slave_addr);
typedef int (*i2c_api_full_io_t)(struct device *dev, typedef int (*i2c_api_full_io_t)(struct device *dev,
uint8_t *tx_buf, uint8_t *tx_buf,
uint32_t tx_len, uint32_t tx_len,
@ -94,9 +90,6 @@ typedef int (*i2c_api_resume_t)(struct device *dev);
struct i2c_driver_api { struct i2c_driver_api {
i2c_api_configure_t configure; i2c_api_configure_t configure;
i2c_api_set_callback_t set_callback; i2c_api_set_callback_t set_callback;
i2c_api_io_t read;
i2c_api_io_t write;
i2c_api_io_t polling_write;
i2c_api_full_io_t transfer; i2c_api_full_io_t transfer;
i2c_api_full_io_t poll_transfer; i2c_api_full_io_t poll_transfer;
i2c_api_suspend_t suspend; i2c_api_suspend_t suspend;
@ -149,7 +142,7 @@ static inline int i2c_write(struct device *dev, uint8_t *buf,
struct i2c_driver_api *api; struct i2c_driver_api *api;
api = (struct i2c_driver_api *)dev->driver_api; api = (struct i2c_driver_api *)dev->driver_api;
return api->write(dev, buf, len, addr); return api->transfer(dev, buf, len, 0, 0, addr, 0);
} }
/** /**
@ -167,7 +160,7 @@ static inline int i2c_read(struct device *dev, uint8_t *buf,
struct i2c_driver_api *api; struct i2c_driver_api *api;
api = (struct i2c_driver_api *)dev->driver_api; api = (struct i2c_driver_api *)dev->driver_api;
return api->read(dev, buf, len, addr); return api->transfer(dev, 0, 0, buf, len, addr, 0);
} }
/** /**
@ -192,11 +185,7 @@ static inline int i2c_polling_write(struct device *dev, uint8_t *buf,
struct i2c_driver_api *api; struct i2c_driver_api *api;
api = (struct i2c_driver_api *)dev->driver_api; api = (struct i2c_driver_api *)dev->driver_api;
if (api && api->polling_write) { return api->poll_transfer(dev, buf, len, 0, 0, addr, 0);
return api->polling_write(dev, buf, len, addr);
} else {
return DEV_INVALID_OP;
}
} }
/** /**
@ -224,12 +213,8 @@ static inline int i2c_transfer(struct device *dev,
struct i2c_driver_api *api; struct i2c_driver_api *api;
api = (struct i2c_driver_api *)dev->driver_api; api = (struct i2c_driver_api *)dev->driver_api;
if (api && api->transfer) { return api->transfer(dev, tx_buf, tx_len,
return api->transfer(dev, tx_buf, tx_len, rx_buf, rx_len, addr, ctrl_flags);
rx_buf, rx_len, addr, ctrl_flags);
} else {
return DEV_INVALID_OP;
}
} }
/** /**
@ -260,12 +245,8 @@ static inline int i2c_poll_transfer(struct device *dev,
struct i2c_driver_api *api; struct i2c_driver_api *api;
api = (struct i2c_driver_api *)dev->driver_api; api = (struct i2c_driver_api *)dev->driver_api;
if (api && api->poll_transfer) { return api->poll_transfer(dev, tx_buf, tx_len,
return api->poll_transfer(dev, tx_buf, tx_len, rx_buf, rx_len, addr, ctrl_flags);
rx_buf, rx_len, addr, ctrl_flags);
} else {
return DEV_INVALID_OP;
}
} }
/** /**