Commit be5c7d72 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

storage: fix i2c eeprom storage

parent 6ae2239e
Pipeline #313 failed with stages
in 11 seconds
...@@ -97,7 +97,9 @@ void bb_i2c_get_byte(struct i2c_bus *bus, uint8_t *data, uint8_t last) ...@@ -97,7 +97,9 @@ void bb_i2c_get_byte(struct i2c_bus *bus, uint8_t *data, uint8_t last)
*data = indata; *data = indata;
} }
void bb_i2c_create(struct i2c_bus *bus, struct gpio_pin *pin_scl, struct gpio_pin *pin_sda ) void bb_i2c_create( struct i2c_bus *bus,
const struct gpio_pin *pin_scl,
const struct gpio_pin *pin_sda )
{ {
bus->pin_scl = pin_scl; bus->pin_scl = pin_scl;
bus->pin_sda = pin_sda; bus->pin_sda = pin_sda;
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "dev/bb_i2c.h" #include "dev/bb_i2c.h"
#include "dev/i2c_eeprom.h" #include "dev/i2c_eeprom.h"
struct i2c_bus i2c_wrc_eeprom;
struct i2c_eeprom_device wrc_eeprom_dev;
int i2c_eeprom_create( struct i2c_eeprom_device *dev, struct i2c_bus *bus, uint8_t i2c_addr, int offset_bytes ) int i2c_eeprom_create( struct i2c_eeprom_device *dev, struct i2c_bus *bus, uint8_t i2c_addr, int offset_bytes )
{ {
dev->bus = bus; dev->bus = bus;
......
...@@ -67,11 +67,6 @@ struct storage_w1_priv ...@@ -67,11 +67,6 @@ struct storage_w1_priv
struct w1_bus *dev; struct w1_bus *dev;
}; };
struct storage_i2c_eeprom_priv
{
struct i2c_eeprom_device *dev;
};
/* Functions for Flash access */ /* Functions for Flash access */
static int sdb_flash_read(struct storage_device *dev, int offset, void *buf, int count) static int sdb_flash_read(struct storage_device *dev, int offset, void *buf, int count)
...@@ -109,6 +104,7 @@ const int32_t spi_flash_default_entry_points[] = ...@@ -109,6 +104,7 @@ const int32_t spi_flash_default_entry_points[] =
0x600000, /* after SVEC AFPGA bitstream */ 0x600000, /* after SVEC AFPGA bitstream */
-1 }; -1 };
const int32_t i2c_eeprom_default_entry_points[] = {0, 64, 128, 256, 512, 1024, -1 };
/* Functions for FRAM access */ /* Functions for FRAM access */
static int sdb_fram_read(struct storage_device *dev, int offset, void *buf, int count) static int sdb_fram_read(struct storage_device *dev, int offset, void *buf, int count)
{ {
...@@ -164,22 +160,23 @@ const struct storage_rwops spi_w1_rwops = { ...@@ -164,22 +160,23 @@ const struct storage_rwops spi_w1_rwops = {
/* The methods for I2C access */ /* The methods for I2C access */
static int sdb_i2c_eeprom_read(struct storage_device *dev, int offset, void *buf, int count) static int sdb_i2c_eeprom_read(struct storage_device *dev, int offset, void *buf, int count)
{ {
struct storage_i2c_eeprom_priv *priv = (struct storage_i2c_eeprom_priv* ) dev->priv; struct i2c_eeprom_device *priv = (struct i2c_eeprom_device* ) dev->priv;
return i2c_eeprom_read(priv->dev, offset, buf, count); return i2c_eeprom_read(priv, offset, buf, count);
} }
static int sdb_i2c_eeprom_write(struct storage_device *dev, int offset, void *buf, int count) static int sdb_i2c_eeprom_write(struct storage_device *dev, int offset, void *buf, int count)
{ {
struct storage_i2c_eeprom_priv *priv = (struct storage_i2c_eeprom_priv* ) dev->priv; struct i2c_eeprom_device *priv = (struct i2c_eeprom_device* ) dev->priv;
return i2c_eeprom_read(priv->dev, offset, buf, count); return i2c_eeprom_write(priv, offset, buf, count);
} }
static int sdb_i2c_eeprom_erase(struct storage_device *dev, int offset, int count) static int sdb_i2c_eeprom_erase(struct storage_device *dev, int offset, int count)
{ {
struct storage_i2c_eeprom_priv *priv = (struct storage_i2c_eeprom_priv* ) dev->priv; struct i2c_eeprom_device *priv = (struct i2c_eeprom_device* ) dev->priv;
return i2c_eeprom_erase(priv->dev, offset, count); return i2c_eeprom_erase(priv, offset, count);
} }
/* Functions for I2C EEPROM access */
const struct storage_rwops i2c_eeprom_rwops = { const struct storage_rwops i2c_eeprom_rwops = {
sdb_i2c_eeprom_read, sdb_i2c_eeprom_read,
sdb_i2c_eeprom_write, sdb_i2c_eeprom_write,
...@@ -200,6 +197,19 @@ void storage_spiflash_create(struct storage_device *dev, struct spi_flash_device ...@@ -200,6 +197,19 @@ void storage_spiflash_create(struct storage_device *dev, struct spi_flash_device
dev->flags = STORAGE_FLAG_DEVICE_OK; dev->flags = STORAGE_FLAG_DEVICE_OK;
} }
void storage_i2ceeprom_create(struct storage_device *dev, struct i2c_eeprom_device *eeprom)
{
static const char* i2c_eeprom_str = "eeprom";
dev->name = (char *) i2c_eeprom_str;
dev->priv = eeprom;
dev->rwops = (struct storage_rwops *) &i2c_eeprom_rwops;
dev->size = 8192;
dev->cfg_entry = 0;
dev->block_size = 32;
dev->entry_points = (int32_t *) i2c_eeprom_default_entry_points;
dev->flags = STORAGE_FLAG_DEVICE_OK;
}
#if 0 #if 0
/* /*
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
struct i2c_bus struct i2c_bus
{ {
struct gpio_pin *pin_scl; const struct gpio_pin *pin_scl;
struct gpio_pin *pin_sda; const struct gpio_pin *pin_sda;
int loop_delay; int loop_delay;
}; };
uint8_t bb_i2c_devprobe(struct i2c_bus *bus, uint8_t i2c_addr); uint8_t bb_i2c_devprobe(struct i2c_bus *bus, uint8_t i2c_addr);
void bb_i2c_create(struct i2c_bus *bus, struct gpio_pin *pin_scl, struct gpio_pin *pin_sda ); void bb_i2c_create(struct i2c_bus *bus, const struct gpio_pin *pin_scl, const struct gpio_pin *pin_sda );
void bb_i2c_init(struct i2c_bus *bus); void bb_i2c_init(struct i2c_bus *bus);
void bb_i2c_start(struct i2c_bus *bus); void bb_i2c_start(struct i2c_bus *bus);
void bb_i2c_repeat_start(struct i2c_bus *bus); void bb_i2c_repeat_start(struct i2c_bus *bus);
......
...@@ -108,6 +108,8 @@ extern volatile struct SYSCON_WB *syscon; ...@@ -108,6 +108,8 @@ extern volatile struct SYSCON_WB *syscon;
extern struct spi_bus spi_wrc_flash; extern struct spi_bus spi_wrc_flash;
extern struct spi_flash_device wrc_flash_dev; extern struct spi_flash_device wrc_flash_dev;
extern struct i2c_bus i2c_wrc_eeprom;
extern struct i2c_eeprom_device wrc_eeprom_dev;
static inline int sysc_get_memsize(void) static inline int sysc_get_memsize(void)
{ {
......
...@@ -115,6 +115,7 @@ struct storage_device ...@@ -115,6 +115,7 @@ struct storage_device
extern struct storage_device wrc_storage_dev; extern struct storage_device wrc_storage_dev;
void storage_spiflash_create(struct storage_device *dev, struct spi_flash_device *flash); void storage_spiflash_create(struct storage_device *dev, struct spi_flash_device *flash);
void storage_i2ceeprom_create(struct storage_device *dev, struct i2c_eeprom_device *eeprom);
void storage_init( struct i2c_bus *bus, int i2c_addr); void storage_init( struct i2c_bus *bus, int i2c_addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment