the rebase auto merge failure, I will resend patches again.

On Fri, Feb 17, 2023 at 10:12 AM ~ssinprem <ssinp...@git.sr.ht> wrote:
>
> From: Sittisak Sinprem <ssinp...@celestica.com>
>
> Signed-off-by: Sittisak Sinprem <ssinp...@celestica.com>
> ---
>  hw/nvram/eeprom_at24c.c | 46 +++++++++++++++++++++++++++++------------
>  1 file changed, 33 insertions(+), 13 deletions(-)
>
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index 3328c32814..0cb650d635 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -41,6 +41,12 @@ struct EEPROMState {
>      uint16_t cur;
>      /* total size in bytes */
>      uint32_t rsize;
> +    /* address byte number
> +     *  for  24c01, 24c02 size <= 256 byte, use only 1 byte
> +     *  otherwise size > 256, use 2 byte
> +     */
> +    uint8_t asize;
> +
>      bool writable;
>      /* cells changed since last START? */
>      bool changed;
> @@ -91,7 +97,7 @@ uint8_t at24c_eeprom_recv(I2CSlave *s)
>      EEPROMState *ee = AT24C_EE(s);
>      uint8_t ret;
>
> -    if (ee->haveaddr == 1) {
> +    if (ee->haveaddr > 0 && ee->haveaddr < ee->asize) {
>          return 0xff;
>      }
>
> @@ -108,11 +114,11 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data)
>  {
>      EEPROMState *ee = AT24C_EE(s);
>
> -    if (ee->haveaddr < 2) {
> +    if (ee->haveaddr < ee->asize) {
>          ee->cur <<= 8;
>          ee->cur |= data;
>          ee->haveaddr++;
> -        if (ee->haveaddr == 2) {
> +        if (ee->haveaddr == ee->asize) {
>              ee->cur %= ee->rsize;
>              DPRINTK("Set pointer %04x\n", ee->cur);
>          }
> @@ -184,6 +190,29 @@ static void at24c_eeprom_realize(DeviceState *dev, Error 
> **errp)
>      }
>
>      ee->mem = g_malloc0(ee->rsize);
> +
> +    /*
> +     * If address size didn't define with property set
> +     *  setting it from Rom size
> +     */
> +    if (ee->asize == 0) {
> +        if (ee->rsize <= 256) {
> +            ee->asize = 1;
> +        } else {
> +            ee->asize = 2;
> +        }
> +    }
> +}
> +
> +static
> +void at24c_eeprom_reset(DeviceState *state)
> +{
> +    EEPROMState *ee = AT24C_EE(state);
> +
> +    ee->changed = false;
> +    ee->cur = 0;
> +    ee->haveaddr = 0;
> +
>      memset(ee->mem, 0, ee->rsize);
>
>      if (ee->init_rom) {
> @@ -201,18 +230,9 @@ static void at24c_eeprom_realize(DeviceState *dev, Error 
> **errp)
>      }
>  }
>
> -static
> -void at24c_eeprom_reset(DeviceState *state)
> -{
> -    EEPROMState *ee = AT24C_EE(state);
> -
> -    ee->changed = false;
> -    ee->cur = 0;
> -    ee->haveaddr = 0;
> -}
> -
>  static Property at24c_eeprom_props[] = {
>      DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0),
> +    DEFINE_PROP_UINT8("address-size", EEPROMState, asize, 0),
>      DEFINE_PROP_BOOL("writable", EEPROMState, writable, true),
>      DEFINE_PROP_DRIVE("drive", EEPROMState, blk),
>      DEFINE_PROP_END_OF_LIST()
> --
> 2.34.6
>

Reply via email to