eeprom: at24: move at24_read() below at24_eeprom_write()
In preparation for splitting at24_eeprom_write() & at24_eeprom_read() into smaller, specialized routines move at24_read() below, so that it won't be intertwined with the low-level EEPROM accessors. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
parent
b0b9f7bf9d
commit
d5bc004798
|
@ -249,38 +249,6 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int at24_read(void *priv, unsigned int off, void *val, size_t count)
|
|
||||||
{
|
|
||||||
struct at24_data *at24 = priv;
|
|
||||||
char *buf = val;
|
|
||||||
|
|
||||||
if (unlikely(!count))
|
|
||||||
return count;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read data from chip, protecting against concurrent updates
|
|
||||||
* from this host, but not from other I2C masters.
|
|
||||||
*/
|
|
||||||
mutex_lock(&at24->lock);
|
|
||||||
|
|
||||||
while (count) {
|
|
||||||
int status;
|
|
||||||
|
|
||||||
status = at24_eeprom_read(at24, buf, off, count);
|
|
||||||
if (status < 0) {
|
|
||||||
mutex_unlock(&at24->lock);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
buf += status;
|
|
||||||
off += status;
|
|
||||||
count -= status;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_unlock(&at24->lock);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note that if the hardware write-protect pin is pulled high, the whole
|
* Note that if the hardware write-protect pin is pulled high, the whole
|
||||||
* chip is normally write protected. But there are plenty of product
|
* chip is normally write protected. But there are plenty of product
|
||||||
|
@ -366,6 +334,38 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int at24_read(void *priv, unsigned int off, void *val, size_t count)
|
||||||
|
{
|
||||||
|
struct at24_data *at24 = priv;
|
||||||
|
char *buf = val;
|
||||||
|
|
||||||
|
if (unlikely(!count))
|
||||||
|
return count;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read data from chip, protecting against concurrent updates
|
||||||
|
* from this host, but not from other I2C masters.
|
||||||
|
*/
|
||||||
|
mutex_lock(&at24->lock);
|
||||||
|
|
||||||
|
while (count) {
|
||||||
|
int status;
|
||||||
|
|
||||||
|
status = at24_eeprom_read(at24, buf, off, count);
|
||||||
|
if (status < 0) {
|
||||||
|
mutex_unlock(&at24->lock);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
buf += status;
|
||||||
|
off += status;
|
||||||
|
count -= status;
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&at24->lock);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int at24_write(void *priv, unsigned int off, void *val, size_t count)
|
static int at24_write(void *priv, unsigned int off, void *val, size_t count)
|
||||||
{
|
{
|
||||||
struct at24_data *at24 = priv;
|
struct at24_data *at24 = priv;
|
||||||
|
|
Loading…
Reference in New Issue