qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sittisak Sinprem <ssinprem@celestica.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-stable@nongnu.org, srikanth@celestica.com,
	kgengan@celestica.com
Subject: Re: [PATCH qemu 1/2] hw/at24c : modify at24c to support 1 byte address mode
Date: Thu, 16 Feb 2023 21:27:19 +0700	[thread overview]
Message-ID: <CAE+aGtVk5R2yZw4_CSLcuX2Ep8hhpq5=s-D4GG5N76Fu7aqQfA@mail.gmail.com> (raw)
In-Reply-To: <CAE+aGtXvEzbKBcnDxTGBVAm+i9t6TN0dX6CEocv2-Napzooe=Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2617 bytes --]

From: Sittisak Sinprem <ssinprem@celestca.com>

Signed-off-by: Sittisak Sinprem <ssinprem@celestca.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

[-- Attachment #2: Type: text/html, Size: 3886 bytes --]

  reply	other threads:[~2023-02-16 14:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  9:54 [PATCH qemu 0/2] hw/at24c support eeprom size less than equal 256 byte ~ssinprem
2023-02-10  6:20 ` [PATCH qemu 1/2] hw/at24c : modify at24c to support 1 byte address mode ~ssinprem
2023-02-14 14:29   ` Cédric Le Goater
2023-02-15 20:39     ` Peter Delevoryas
2023-02-16  8:25   ` Philippe Mathieu-Daudé
2023-02-16  8:47     ` Sittisak Sinprem
2023-02-16 14:27       ` Sittisak Sinprem [this message]
2023-02-14  9:06 ` [PATCH qemu 2/2] aspeed/fuji : correct the eeprom size ~ssinprem
2023-02-14 14:28   ` Cédric Le Goater
2023-02-15  3:17     ` Sittisak Sinprem
2023-02-15 20:34     ` Peter Delevoryas
2023-02-16 14:23       ` Sittisak Sinprem
2023-02-16 18:43         ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE+aGtVk5R2yZw4_CSLcuX2Ep8hhpq5=s-D4GG5N76Fu7aqQfA@mail.gmail.com' \
    --to=ssinprem@celestica.com \
    --cc=kgengan@celestica.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=srikanth@celestica.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).