Move i2c_eeprom to mem/ directory
This commit is contained in:
@@ -33,7 +33,7 @@ typedef struct {
|
||||
uint8_t addr_len, addr_pos;
|
||||
} i2c_eeprom_t;
|
||||
|
||||
|
||||
#define ENABLE_I2C_EEPROM_LOG 1
|
||||
#ifdef ENABLE_I2C_EEPROM_LOG
|
||||
int i2c_eeprom_do_log = ENABLE_I2C_EEPROM_LOG;
|
||||
|
||||
@@ -54,35 +54,37 @@ i2c_eeprom_log(const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t
|
||||
static uint8_t
|
||||
i2c_eeprom_start(void *bus, uint8_t addr, uint8_t read, void *priv)
|
||||
{
|
||||
i2c_eeprom_t *dev = (i2c_eeprom_t *) priv;
|
||||
|
||||
i2c_eeprom_log("I2C EEPROM %s %02X: start()\n", i2c_getbusname(dev->i2c), dev->addr);
|
||||
|
||||
if (!read) {
|
||||
dev->addr_pos = 0;
|
||||
dev->addr_register = (addr << dev->addr_len) & dev->addr_mask;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
static uint8_t
|
||||
i2c_eeprom_read(void *bus, uint8_t addr, void *priv)
|
||||
{
|
||||
i2c_eeprom_t *dev = (i2c_eeprom_t *) priv;
|
||||
uint8_t ret = dev->data[dev->addr_register];
|
||||
|
||||
i2c_eeprom_log("I2C EEPROM %s %02X: read(%06X) = %02X\n", i2c_getbusname(dev->i2c), dev->addr, dev->addr_register, ret);
|
||||
if (++dev->addr_register > dev->addr_mask) /* roll-over */
|
||||
dev->addr_register = 0;
|
||||
dev->addr_register++;
|
||||
dev->addr_register &= dev->addr_mask; /* roll-over */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
static uint8_t
|
||||
i2c_eeprom_write(void *bus, uint8_t addr, uint8_t data, void *priv)
|
||||
{
|
||||
i2c_eeprom_t *dev = (i2c_eeprom_t *) priv;
|
||||
@@ -93,14 +95,14 @@ i2c_eeprom_write(void *bus, uint8_t addr, uint8_t data, void *priv)
|
||||
dev->addr_register &= (1 << dev->addr_len) - 1;
|
||||
dev->addr_register |= addr << dev->addr_len;
|
||||
dev->addr_register &= dev->addr_mask;
|
||||
i2c_eeprom_log("I2C EEPROM %s %02X: write(address, %04X)\n", i2c_getbusname(dev->i2c), dev->addr, dev->addr_register);
|
||||
i2c_eeprom_log("I2C EEPROM %s %02X: write(address, %06X)\n", i2c_getbusname(dev->i2c), dev->addr, dev->addr_register);
|
||||
dev->addr_pos += 8;
|
||||
} else {
|
||||
i2c_eeprom_log("I2C EEPROM %s %02X: write(%06X, %02X) = %d\n", i2c_getbusname(dev->i2c), dev->addr, dev->addr_register, data, !!dev->writable);
|
||||
if (dev->writable)
|
||||
dev->data[dev->addr_register] = data;
|
||||
if (++dev->addr_register > dev->addr_mask) /* roll-over */
|
||||
dev->addr_register = 0;
|
||||
dev->addr_register++;
|
||||
dev->addr_register &= dev->addr_mask; /* roll-over */
|
||||
return dev->writable;
|
||||
}
|
||||
|
||||
@@ -108,12 +110,26 @@ i2c_eeprom_write(void *bus, uint8_t addr, uint8_t data, void *priv)
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
log2i(uint32_t i)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
while ((i >>= 1))
|
||||
ret++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
i2c_eeprom_init(void *i2c, uint8_t addr, uint8_t *data, uint32_t size, uint8_t writable)
|
||||
{
|
||||
i2c_eeprom_t *dev = (i2c_eeprom_t *) malloc(sizeof(i2c_eeprom_t));
|
||||
memset(dev, 0, sizeof(i2c_eeprom_t));
|
||||
|
||||
/* Round size up to the next power of 2. */
|
||||
uint32_t pow_size = 1 << log2i(size);
|
||||
if (pow_size < size)
|
||||
size = pow_size << 1;
|
||||
size &= 0x7fffff; /* address space limit of 8 MB = 7 bits from I2C address + 16 bits */
|
||||
|
||||
i2c_eeprom_log("I2C EEPROM %s %02X: init(%d, %d)\n", i2c_getbusname(i2c), addr, size, writable);
|
@@ -622,7 +622,7 @@ MAINOBJ := pc.o config.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \
|
||||
usb.o device.o nvr.o nvr_at.o nvr_ps2.o \
|
||||
$(VNCOBJ)
|
||||
|
||||
MEMOBJ := catalyst_flash.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o
|
||||
MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o
|
||||
|
||||
CPUOBJ := cpu.o cpu_table.o \
|
||||
808x.o 386.o 386_common.o 386_dynarec.o 386_dynarec_ops.o $(CGTOBJ) \
|
||||
@@ -654,7 +654,7 @@ MCHOBJ := machine.o machine_table.o \
|
||||
|
||||
DEVOBJ := bugger.o hwm.o hwm_lm75.o hwm_lm78.o hwm_gl518sm.o hwm_vt82c686.o ibm_5161.o isamem.o isartc.o \
|
||||
lpt.o pci_bridge.o postcard.o serial.o vpc2007.o \
|
||||
i2c.o i2c_eeprom.o i2c_gpio.o smbus_piix4.o \
|
||||
i2c.o i2c_gpio.o smbus_piix4.o \
|
||||
keyboard.o \
|
||||
keyboard_xt.o keyboard_at.o \
|
||||
mouse.o \
|
||||
|
Reference in New Issue
Block a user