diff mbox series

[qemu] arm: aspeed: Add palmetto and evb EEPROM I2C devices

Message ID 20170915061830.1527-1-joel@jms.id.au
State Not Applicable, archived
Headers show
Series [qemu] arm: aspeed: Add palmetto and evb EEPROM I2C devices | expand

Commit Message

Joel Stanley Sept. 15, 2017, 6:18 a.m. UTC
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 hw/arm/aspeed.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Cédric Le Goater Sept. 15, 2017, 7:25 a.m. UTC | #1
On 09/15/2017 08:18 AM, Joel Stanley wrote:
> Signed-off-by: Joel Stanley <joel@jms.id.au>

We could fill the eeprom_buf with some valid data if needed.

Reviewed-by: Cédric Le Goater <clg@kaod.org>

> ---
>  hw/arm/aspeed.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
> index 9ef5fb3b6ddc..2f596959649a 100644
> --- a/hw/arm/aspeed.c
> +++ b/hw/arm/aspeed.c
> @@ -253,6 +253,7 @@ static void aspeed_board_init(MachineState *machine,
>  
>  static void palmetto_bmc_i2c_init(AspeedBoardState *bmc)
>  {
> +    uint8_t *eeprom_buf = g_malloc0(256 * 1024);
>      AspeedSoCState *soc = &bmc->soc;
>      DeviceState *dev;
>  
> @@ -260,6 +261,13 @@ static void palmetto_bmc_i2c_init(AspeedBoardState *bmc)
>       * enough to provide basic RTC features. Alarms will be missing */
>      i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), "ds1338", 0x68);
>  
> +    /* 256KB EEPROM */
> +    dev = qdev_create((BusState *) aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0),
> +                      "smbus-eeprom");
> +    qdev_prop_set_uint8(dev, "address", 0x50);
> +    qdev_prop_set_ptr(dev, "data", eeprom_buf);
> +    qdev_init_nofail(dev);
> +
>      /* add a TMP423 temperature sensor */
>      dev = i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2),
>                             "tmp423", 0x4c);
> @@ -295,7 +303,15 @@ static const TypeInfo palmetto_bmc_type = {
>  
>  static void ast2500_evb_i2c_init(AspeedBoardState *bmc)
>  {
> +    uint8_t *eeprom_buf = g_malloc0(8 * 1024);
>      AspeedSoCState *soc = &bmc->soc;
> +    DeviceState *dev;
> +
> +    dev = qdev_create((BusState *) aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3),
> +                      "smbus-eeprom");
> +    qdev_prop_set_uint8(dev, "address", 0x50);
> +    qdev_prop_set_ptr(dev, "data", eeprom_buf);
> +    qdev_init_nofail(dev);
>  
>      /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
>      i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0x4d);
>
Joel Stanley Sept. 18, 2017, 3:26 a.m. UTC | #2
On Fri, Sep 15, 2017 at 4:55 PM, Cédric Le Goater <clg@kaod.org> wrote:
> On 09/15/2017 08:18 AM, Joel Stanley wrote:
>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>
> We could fill the eeprom_buf with some valid data if needed.



That's a good idea.

When I use this I see the following error:

# pwd
/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c@1e78a000/1e78a100.i2c-bus
# hexdump -C i2c-0/0-0050/eeprom
hexdump: i2c-0/0-0050/eeprom: Operation timed out
00000000  74 65 73 74 20 64 61 74  61 0a 00 00 00 00 00     |test data......|
0000000f

A strace shows three reads, with the first succeeding and the second
two failing:

# strace hexdump -C i2c-0/0-0050/eeprom
execve("/usr/bin/hexdump", ["hexdump", "-C", "i2c-0/0-0050/eeprom"],
[/* 12 vars */]) = 0
set_tls(0x76fad764, 0x3c, 0x76fac47c, 0x24, 0x76fad698) = 0
set_tid_address(0x76fad6b4)             = 581
getuid32()                              = 0
open("i2c-0/0-0050/eeprom", O_RDONLY|O_LARGEFILE) = 3
dup2(3, 0)                              = 0
close(3)                                = 0
readv(0, [{iov_base="test data\n\0\0\0\0\0", iov_len=15},
{iov_base="", iov_len=1024}], 2) = 15
readv(0, 0x7e898cd4, 2)                 = -1 ETIMEDOUT (Operation timed out)
readv(0, 0x7e898cd4, 2)                 = -1 ETIMEDOUT (Operation timed out)
write(2, "hexdump: i2c-0/0-0050/eeprom: Op"..., 50hexdump:
i2c-0/0-0050/eeprom: Operation timed out
) = 50
ioctl(1, TIOCGWINSZ, {ws_row=0, ws_col=0, ws_xpixel=0, ws_ypixel=0}) = 0
writev(1, [{iov_base="00000000  74 65 73 74 20 64 61 7"...,
iov_len=76}, {iov_base="|\n", iov_len=2}], 200000000  74 65 73 74 20
64 61 74  61 0a 00 00 00 00 00     |test data......|
) = 78
writev(1, [{iov_base="0000000f", iov_len=8}, {iov_base="\n",
iov_len=1}], 20000000f
) = 9
exit_group(0)                           = ?
+++ exited with 0 +++

Any ideas there?

Cheers,

Joel
Cédric Le Goater Sept. 18, 2017, 7:59 a.m. UTC | #3
On 09/18/2017 05:26 AM, Joel Stanley wrote:
> On Fri, Sep 15, 2017 at 4:55 PM, Cédric Le Goater <clg@kaod.org> wrote:
>> On 09/15/2017 08:18 AM, Joel Stanley wrote:
>>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>>
>> We could fill the eeprom_buf with some valid data if needed.
> 
> 
> 
> That's a good idea.
> 
> When I use this I see the following error:
> 
> # pwd
> /sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c@1e78a000/1e78a100.i2c-bus

hmm, the address is I2C bus 3.

> # hexdump -C i2c-0/0-0050/eeprom

But you use bus 0 ? weird.

> hexdump: i2c-0/0-0050/eeprom: Operation timed out
> 00000000  74 65 73 74 20 64 61 74  61 0a 00 00 00 00 00     |test data......|
> 0000000f
> 
> A strace shows three reads, with the first succeeding and the second
> two failing:
> 
> # strace hexdump -C i2c-0/0-0050/eeprom
> execve("/usr/bin/hexdump", ["hexdump", "-C", "i2c-0/0-0050/eeprom"],
> [/* 12 vars */]) = 0
> set_tls(0x76fad764, 0x3c, 0x76fac47c, 0x24, 0x76fad698) = 0
> set_tid_address(0x76fad6b4)             = 581
> getuid32()                              = 0
> open("i2c-0/0-0050/eeprom", O_RDONLY|O_LARGEFILE) = 3
> dup2(3, 0)                              = 0
> close(3)                                = 0
> readv(0, [{iov_base="test data\n\0\0\0\0\0", iov_len=15},
> {iov_base="", iov_len=1024}], 2) = 15
> readv(0, 0x7e898cd4, 2)                 = -1 ETIMEDOUT (Operation timed out)
> readv(0, 0x7e898cd4, 2)                 = -1 ETIMEDOUT (Operation timed out)
> write(2, "hexdump: i2c-0/0-0050/eeprom: Op"..., 50hexdump:
> i2c-0/0-0050/eeprom: Operation timed out
> ) = 50
> ioctl(1, TIOCGWINSZ, {ws_row=0, ws_col=0, ws_xpixel=0, ws_ypixel=0}) = 0
> writev(1, [{iov_base="00000000  74 65 73 74 20 64 61 7"...,
> iov_len=76}, {iov_base="|\n", iov_len=2}], 200000000  74 65 73 74 20
> 64 61 74  61 0a 00 00 00 00 00     |test data......|
> ) = 78
> writev(1, [{iov_base="0000000f", iov_len=8}, {iov_base="\n",
> iov_len=1}], 20000000f
> ) = 9
> exit_group(0)                           = ?
> +++ exited with 0 +++
> 
> Any ideas there?


If I use your patch adding the eeprom to bus 0 on the palmetto machine, I don't 
see any issues while reading the contents.

  hexdump -C  /sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c@1e78a000/1e78a040.i2c-bus/i2c-0/0-0050/eeprom
  00000000  00 80 80 80 80 80 80 80  80 80 80 80 80 80 80 80  |................|
  00000010  80 80 80 80 80 80 80 80  80 80 80 80 80 80 80 80  |................|
  *
  ...
  00007f80  80 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  00007f90  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  *
  00008000


Cheers,

C.
Joel Stanley Sept. 18, 2017, 12:49 p.m. UTC | #4
On Mon, Sep 18, 2017 at 5:29 PM, Cédric Le Goater <clg@kaod.org> wrote:
> On 09/18/2017 05:26 AM, Joel Stanley wrote:
>> On Fri, Sep 15, 2017 at 4:55 PM, Cédric Le Goater <clg@kaod.org> wrote:
>>> On 09/15/2017 08:18 AM, Joel Stanley wrote:
>>>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>>>
>>> We could fill the eeprom_buf with some valid data if needed.
>>
>>
>>
>> That's a good idea.
>>
>> When I use this I see the following error:
>>
>> # pwd
>> /sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c@1e78a000/1e78a100.i2c-bus
>
> hmm, the address is I2C bus 3.
>
>> # hexdump -C i2c-0/0-0050/eeprom
>
> But you use bus 0 ? weird.

The devicetree I was using lacked aliases. I fixed this (so bus 3
shows up at i2c-0), and I get the same results.

Palmetto worked fine for me, so it's just the EVB produces this behaviour.

Cheers,

Joel
diff mbox series

Patch

diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index 9ef5fb3b6ddc..2f596959649a 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -253,6 +253,7 @@  static void aspeed_board_init(MachineState *machine,
 
 static void palmetto_bmc_i2c_init(AspeedBoardState *bmc)
 {
+    uint8_t *eeprom_buf = g_malloc0(256 * 1024);
     AspeedSoCState *soc = &bmc->soc;
     DeviceState *dev;
 
@@ -260,6 +261,13 @@  static void palmetto_bmc_i2c_init(AspeedBoardState *bmc)
      * enough to provide basic RTC features. Alarms will be missing */
     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), "ds1338", 0x68);
 
+    /* 256KB EEPROM */
+    dev = qdev_create((BusState *) aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0),
+                      "smbus-eeprom");
+    qdev_prop_set_uint8(dev, "address", 0x50);
+    qdev_prop_set_ptr(dev, "data", eeprom_buf);
+    qdev_init_nofail(dev);
+
     /* add a TMP423 temperature sensor */
     dev = i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2),
                            "tmp423", 0x4c);
@@ -295,7 +303,15 @@  static const TypeInfo palmetto_bmc_type = {
 
 static void ast2500_evb_i2c_init(AspeedBoardState *bmc)
 {
+    uint8_t *eeprom_buf = g_malloc0(8 * 1024);
     AspeedSoCState *soc = &bmc->soc;
+    DeviceState *dev;
+
+    dev = qdev_create((BusState *) aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3),
+                      "smbus-eeprom");
+    qdev_prop_set_uint8(dev, "address", 0x50);
+    qdev_prop_set_ptr(dev, "data", eeprom_buf);
+    qdev_init_nofail(dev);
 
     /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0x4d);