From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 150840759881112.293210478100036; Thu, 19 Oct 2017 03:06:38 -0700 (PDT) Received: from localhost ([::1]:48458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57if-0003x6-6y for importer@patchew.org; Thu, 19 Oct 2017 06:06:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57go-0002nN-Ly for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57gk-0007wA-Mf for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:34 -0400 Received: from 17.mo5.mail-out.ovh.net ([46.105.56.132]:43800) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57gk-0007v6-GW for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:30 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id 103A7145A18 for ; Thu, 19 Oct 2017 12:04:29 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id 4B2F280079; Thu, 19 Oct 2017 12:04:21 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:03 +0200 Message-Id: <20171019100410.26239-2-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8695324982241430289 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.56.132 Subject: [Qemu-devel] [PATCH v4 1/8] aspeed: introduce a dummy ROM device to catch invalid writes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some legacy firmwares access unimplemented addresses on the Aspeed SoC (old U-Boot code using variables in the bss when it shouldn't do). Let's add a dummy ROM device to catch the invalid writes and support new board without using the 'ignore_memory_transaction_failures' flags. Signed-off-by: C=C3=A9dric Le Goater --- hw/arm/aspeed.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index ab895ad490af..e44733153819 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -166,6 +166,19 @@ static void aspeed_board_init_flashes(AspeedSMCState *= s, const char *flashtype, } } =20 +static void boot_rom_rw_flash_write(void *opaque, hwaddr offset, uint64_t = value, + unsigned size) +{ + qemu_log_mask(LOG_GUEST_ERROR, + "%s: 0x%" HWADDR_PRIx " <- 0x%" PRIx64 " [%u]\n", + __func__, offset, value, size); +} + +static const MemoryRegionOps boot_rom_rw_flash_ops =3D { + .write =3D boot_rom_rw_flash_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, +}; + static void aspeed_board_init(MachineState *machine, const AspeedBoardConfig *cfg) { @@ -209,6 +222,7 @@ static void aspeed_board_init(MachineState *machine, if (drive0) { AspeedSMCFlash *fl =3D &bmc->soc.fmc.flashes[0]; MemoryRegion *boot_rom =3D g_new(MemoryRegion, 1); + MemoryRegion *boot_rom_rw =3D g_new(MemoryRegion, 1); =20 /* * create a ROM region using the default mapping window size of @@ -221,6 +235,16 @@ static void aspeed_board_init(MachineState *machine, memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR, boot_rom); write_boot_rom(drive0, FIRMWARE_ADDR, fl->size, &error_abort); + + /* + * Create a fake ROM region to track invalid writes done by + * some legacy firmwares + */ + memory_region_init_rom_device(boot_rom_rw, NULL, &boot_rom_rw_flas= h_ops, + NULL, "aspeed.boot_rom_rw", fl->size, + &error_abort); + memory_region_add_subregion_overlap(get_system_memory(), FIRMWARE_= ADDR, + boot_rom_rw, 0); } =20 aspeed_board_binfo.kernel_filename =3D machine->kernel_filename; --=20 2.13.6 From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508407753595262.6649250716524; Thu, 19 Oct 2017 03:09:13 -0700 (PDT) Received: from localhost ([::1]:48472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57lA-0006Fr-Rm for importer@patchew.org; Thu, 19 Oct 2017 06:09:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57gu-0002q0-0X for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57gr-00081Z-Dn for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:40 -0400 Received: from 8.mo5.mail-out.ovh.net ([178.32.116.78]:56150) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57gr-00080g-6m for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:37 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id B7D5514173A for ; Thu, 19 Oct 2017 12:04:35 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id 7C63580079; Thu, 19 Oct 2017 12:04:28 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:04 +0200 Message-Id: <20171019100410.26239-3-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8697295307900881681 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.32.116.78 Subject: [Qemu-devel] [PATCH v4 2/8] aspeed: remove ignore_memory_transaction_failures on all boards X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that we have a dummy ROM device catching the invalid writes, we can remove this flag and work on fixing the current firwmares still accessing unimplemented addresses. Signed-off-by: C=C3=A9dric Le Goater --- hw/arm/aspeed.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index e44733153819..dbb02f568462 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -294,7 +294,6 @@ static void palmetto_bmc_class_init(ObjectClass *oc, vo= id *data) mc->no_floppy =3D 1; mc->no_cdrom =3D 1; mc->no_parallel =3D 1; - mc->ignore_memory_transaction_failures =3D true; } =20 static const TypeInfo palmetto_bmc_type =3D { @@ -327,7 +326,6 @@ static void ast2500_evb_class_init(ObjectClass *oc, voi= d *data) mc->no_floppy =3D 1; mc->no_cdrom =3D 1; mc->no_parallel =3D 1; - mc->ignore_memory_transaction_failures =3D true; } =20 static const TypeInfo ast2500_evb_type =3D { @@ -352,7 +350,6 @@ static void romulus_bmc_class_init(ObjectClass *oc, voi= d *data) mc->no_floppy =3D 1; mc->no_cdrom =3D 1; mc->no_parallel =3D 1; - mc->ignore_memory_transaction_failures =3D true; } =20 static const TypeInfo romulus_bmc_type =3D { --=20 2.13.6 From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508407758400975.4442093838036; Thu, 19 Oct 2017 03:09:18 -0700 (PDT) Received: from localhost ([::1]:48473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57lI-0006QE-KL for importer@patchew.org; Thu, 19 Oct 2017 06:09:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57h4-0002wY-Od for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57gy-00087o-Ky for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:50 -0400 Received: from 7.mo5.mail-out.ovh.net ([178.32.124.100]:36352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57gy-00086e-FW for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:44 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id E986811B6F6 for ; Thu, 19 Oct 2017 12:04:42 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id AD27B80089; Thu, 19 Oct 2017 12:04:35 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:05 +0200 Message-Id: <20171019100410.26239-4-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8699265632657902353 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.32.124.100 Subject: [Qemu-devel] [PATCH v4 3/8] aspeed: add support for the witherspoon-bmc board X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The Witherspoon boards are OpenPOWER system hosting POWER9 Processors. Let's add support for their BMC including a couple of I2C devices as found on real HW. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Andrew Jeffery --- Changes since v2: - removed 'ignore_memory_transaction_failures' flag on the machine. - Added a comment on the I2C device used. hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index dbb02f568462..9e1f8b80d2a5 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -46,6 +46,7 @@ enum { PALMETTO_BMC, AST2500_EVB, ROMULUS_BMC, + WITHERSPOON_BMC, }; =20 /* Palmetto hardware value: 0x120CE416 */ @@ -83,8 +84,12 @@ enum { SCU_AST2500_HW_STRAP_ACPI_ENABLE | \ SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER)) =20 +/* Witherspoon hardware value: 0xF10AD216 (but use romulus definition) */ +#define WITHERSPOON_BMC_HW_STRAP1 ROMULUS_BMC_HW_STRAP1 + static void palmetto_bmc_i2c_init(AspeedBoardState *bmc); static void ast2500_evb_i2c_init(AspeedBoardState *bmc); +static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc); =20 static const AspeedBoardConfig aspeed_boards[] =3D { [PALMETTO_BMC] =3D { @@ -110,6 +115,14 @@ static const AspeedBoardConfig aspeed_boards[] =3D { .spi_model =3D "mx66l1g45g", .num_cs =3D 2, }, + [WITHERSPOON_BMC] =3D { + .soc_name =3D "ast2500-a1", + .hw_strap1 =3D WITHERSPOON_BMC_HW_STRAP1, + .fmc_model =3D "mx25l25635e", + .spi_model =3D "mx66l1g45g", + .num_cs =3D 2, + .i2c_init =3D witherspoon_bmc_i2c_init, + }, }; =20 #define FIRMWARE_ADDR 0x0 @@ -358,11 +371,47 @@ static const TypeInfo romulus_bmc_type =3D { .class_init =3D romulus_bmc_class_init, }; =20 +static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc) +{ + AspeedSoCState *soc =3D &bmc->soc; + + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "tmp423", 0= x4c); + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 5), "tmp423", 0= x4c); + + /* The Witherspoon expects a TMP275 but a TMP105 is compatible */ + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "tmp105", 0= x4a); +} + +static void witherspoon_bmc_init(MachineState *machine) +{ + aspeed_board_init(machine, &aspeed_boards[WITHERSPOON_BMC]); +} + +static void witherspoon_bmc_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->desc =3D "OpenPOWER Witherspoon BMC (ARM1176)"; + mc->init =3D witherspoon_bmc_init; + mc->max_cpus =3D 1; + mc->no_sdcard =3D 1; + mc->no_floppy =3D 1; + mc->no_cdrom =3D 1; + mc->no_parallel =3D 1; +} + +static const TypeInfo witherspoon_bmc_type =3D { + .name =3D MACHINE_TYPE_NAME("witherspoon-bmc"), + .parent =3D TYPE_MACHINE, + .class_init =3D witherspoon_bmc_class_init, +}; + static void aspeed_machine_init(void) { type_register_static(&palmetto_bmc_type); type_register_static(&ast2500_evb_type); type_register_static(&romulus_bmc_type); + type_register_static(&witherspoon_bmc_type); } =20 type_init(aspeed_machine_init) --=20 2.13.6 From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508407627116130.99341042148205; Thu, 19 Oct 2017 03:07:07 -0700 (PDT) Received: from localhost ([::1]:48459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57jB-0004Mr-9l for importer@patchew.org; Thu, 19 Oct 2017 06:07:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57hB-00033S-J1 for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57h5-0008Gy-RW for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:57 -0400 Received: from 18.mo5.mail-out.ovh.net ([178.33.45.10]:59376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57h5-0008Ev-Kl for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:51 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id 24DC41406BC for ; Thu, 19 Oct 2017 12:04:50 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id DC53580089; Thu, 19 Oct 2017 12:04:42 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:06 +0200 Message-Id: <20171019100410.26239-5-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8701517433232853777 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.45.10 Subject: [Qemu-devel] [PATCH v4 4/8] aspeed: add an I2C RTC device to all machines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The AST2500 EVB does not have an RTC but we can pretend that one is plugged on the I2C bus header. The romulus and witherspoon boards expects an Epson RX8900 I2C RTC but a ds1338 is good enough for the basic features we need. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Andrew Jeffery --- hw/arm/aspeed.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index 9e1f8b80d2a5..8683388e632c 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -89,6 +89,7 @@ enum { =20 static void palmetto_bmc_i2c_init(AspeedBoardState *bmc); static void ast2500_evb_i2c_init(AspeedBoardState *bmc); +static void romulus_bmc_i2c_init(AspeedBoardState *bmc); static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc); =20 static const AspeedBoardConfig aspeed_boards[] =3D { @@ -114,6 +115,7 @@ static const AspeedBoardConfig aspeed_boards[] =3D { .fmc_model =3D "n25q256a", .spi_model =3D "mx66l1g45g", .num_cs =3D 2, + .i2c_init =3D romulus_bmc_i2c_init, }, [WITHERSPOON_BMC] =3D { .soc_name =3D "ast2500-a1", @@ -321,6 +323,10 @@ static void ast2500_evb_i2c_init(AspeedBoardState *bmc) =20 /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0= x4d); + + /* The AST2500 EVB does not have an RTC. Let's pretend that one is + * plugged on the I2C bus header */ + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", = 0x32); } =20 static void ast2500_evb_init(MachineState *machine) @@ -347,6 +353,15 @@ static const TypeInfo ast2500_evb_type =3D { .class_init =3D ast2500_evb_class_init, }; =20 +static void romulus_bmc_i2c_init(AspeedBoardState *bmc) +{ + AspeedSoCState *soc =3D &bmc->soc; + + /* The romulus board expects Epson RX8900 I2C RTC but a ds1338 is + * good enough */ + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", = 0x32); +} + static void romulus_bmc_init(MachineState *machine) { aspeed_board_init(machine, &aspeed_boards[ROMULUS_BMC]); @@ -380,6 +395,10 @@ static void witherspoon_bmc_i2c_init(AspeedBoardState = *bmc) =20 /* The Witherspoon expects a TMP275 but a TMP105 is compatible */ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "tmp105", 0= x4a); + + /* The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is + * good enough */ + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", = 0x32); } =20 static void witherspoon_bmc_init(MachineState *machine) --=20 2.13.6 From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508407633741762.7483192233576; Thu, 19 Oct 2017 03:07:13 -0700 (PDT) Received: from localhost ([::1]:48460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57jH-0004Ti-Uo for importer@patchew.org; Thu, 19 Oct 2017 06:07:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57hF-00036i-KA for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57hC-0008Mt-Vn for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:01 -0400 Received: from 16.mo5.mail-out.ovh.net ([87.98.174.144]:55353) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57hC-0008LT-Px for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:04:58 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id 4BC30141817 for ; Thu, 19 Oct 2017 12:04:57 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id 1749480093; Thu, 19 Oct 2017 12:04:50 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:07 +0200 Message-Id: <20171019100410.26239-6-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8703487757119228689 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.174.144 Subject: [Qemu-devel] [PATCH v4 5/8] smbus: add a smbus_eeprom_init_one() routine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is an helper routine to add a single EEPROM on an I2C bus. It can be directly used by smbus_eeprom_init() which adds a certain number of EEPROMs on mips and x86 machines. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/i2c/smbus_eeprom.c | 16 +++++++++++----- include/hw/i2c/smbus.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index b13ec0fe7a2a..2d24a4cd59bf 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -140,6 +140,16 @@ static void smbus_eeprom_register_types(void) =20 type_init(smbus_eeprom_register_types) =20 +void smbus_eeprom_init_one(I2CBus *smbus, uint8_t address, uint8_t *eeprom= _buf) +{ + DeviceState *dev; + + dev =3D qdev_create((BusState *) smbus, "smbus-eeprom"); + qdev_prop_set_uint8(dev, "address", address); + qdev_prop_set_ptr(dev, "data", eeprom_buf); + qdev_init_nofail(dev); +} + void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom, const uint8_t *eeprom_spd, int eeprom_spd_size) { @@ -150,10 +160,6 @@ void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom, } =20 for (i =3D 0; i < nb_eeprom; i++) { - DeviceState *eeprom; - eeprom =3D qdev_create((BusState *)smbus, "smbus-eeprom"); - qdev_prop_set_uint8(eeprom, "address", 0x50 + i); - qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256)); - qdev_init_nofail(eeprom); + smbus_eeprom_init_one(smbus, 0x50 + i, eeprom_buf + (i * 256)); } } diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h index 544bbc19574f..666cdeb04c07 100644 --- a/include/hw/i2c/smbus.h +++ b/include/hw/i2c/smbus.h @@ -77,6 +77,7 @@ int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t c= ommand, uint8_t *data); int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t = *data, int len); =20 +void smbus_eeprom_init_one(I2CBus *smbus, uint8_t address, uint8_t *eeprom= _buf); void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom, const uint8_t *eeprom_spd, int size); =20 --=20 2.13.6 From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508407882820155.88920381448145; Thu, 19 Oct 2017 03:11:22 -0700 (PDT) Received: from localhost ([::1]:48487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57nJ-0000F8-1T for importer@patchew.org; Thu, 19 Oct 2017 06:11:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57hN-0003D3-0S for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57hK-0008T6-Ak for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:08 -0400 Received: from 9.mo5.mail-out.ovh.net ([178.32.96.204]:37829) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57hK-0008SA-5N for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:06 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id 7E050144545 for ; Thu, 19 Oct 2017 12:05:04 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id 476A38007B; Thu, 19 Oct 2017 12:04:57 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:08 +0200 Message-Id: <20171019100410.26239-7-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8705458083310832401 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.32.96.204 Subject: [Qemu-devel] [PATCH v4 6/8] aspeed: Add EEPROM I2C devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The Aspeed boards have at least one EEPROM to hold the Vital Product Data (VPD). Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Andrew Jeffery --- hw/arm/aspeed.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index 8683388e632c..2e08eb49f443 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -17,6 +17,7 @@ #include "hw/arm/arm.h" #include "hw/arm/aspeed_soc.h" #include "hw/boards.h" +#include "hw/i2c/smbus.h" #include "qemu/log.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" @@ -279,11 +280,15 @@ static void palmetto_bmc_i2c_init(AspeedBoardState *b= mc) { AspeedSoCState *soc =3D &bmc->soc; DeviceState *dev; + uint8_t *eeprom_buf =3D g_malloc0(32 * 1024); =20 /* The palmetto platform expects a ds3231 RTC but a ds1338 is * enough to provide basic RTC features. Alarms will be missing */ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), "ds1338", 0= x68); =20 + smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), 0x50, + eeprom_buf); + /* add a TMP423 temperature sensor */ dev =3D i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2), "tmp423", 0x4c); @@ -320,6 +325,10 @@ static const TypeInfo palmetto_bmc_type =3D { static void ast2500_evb_i2c_init(AspeedBoardState *bmc) { AspeedSoCState *soc =3D &bmc->soc; + uint8_t *eeprom_buf =3D g_malloc0(8 * 1024); + + smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), 0x50, + eeprom_buf); =20 /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0= x4d); @@ -389,6 +398,7 @@ static const TypeInfo romulus_bmc_type =3D { static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc) { AspeedSoCState *soc =3D &bmc->soc; + uint8_t *eeprom_buf =3D g_malloc0(8 * 1024); =20 i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "tmp423", 0= x4c); i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 5), "tmp423", 0= x4c); @@ -399,6 +409,9 @@ static void witherspoon_bmc_i2c_init(AspeedBoardState *= bmc) /* The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is * good enough */ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", = 0x32); + + smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), 0x51, + eeprom_buf); } =20 static void witherspoon_bmc_init(MachineState *machine) --=20 2.13.6 From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508407904905353.59020258855026; Thu, 19 Oct 2017 03:11:44 -0700 (PDT) Received: from localhost ([::1]:48489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57nZ-0000Sz-Jt for importer@patchew.org; Thu, 19 Oct 2017 06:11:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57hV-0003NF-45 for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57hS-0000Dm-AY for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:17 -0400 Received: from 12.mo5.mail-out.ovh.net ([46.105.39.65]:54845) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57hR-0000B1-Mr for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:14 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id E25AE145323 for ; Thu, 19 Oct 2017 12:05:11 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id 76F3D80099; Thu, 19 Oct 2017 12:05:04 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:09 +0200 Message-Id: <20171019100410.26239-8-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8707428406999550737 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.39.65 Subject: [Qemu-devel] [PATCH v4 7/8] misc: add pca9552 LED blinker model X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Specs are available here : https://www.nxp.com/docs/en/application-note/AN264.pdf This is a simple model supporting the basic registers for led and GPIO mode. The device also supports two blinking rates but not the model yet. Signed-off-by: C=C3=A9dric Le Goater --- Changes since v3: - introduced auto-increment support - removed the buffer collecting bytes on the bus - improved reset - used extract32 - added a unit test Changes since v2: - removed comments on the I2C buffer size, but kept the array. I did not want to rewrite the buffer handling default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/pca9552.c | 259 ++++++++++++++++++++++++++++++++++++= ++++ include/hw/misc/pca9552.h | 33 +++++ tests/Makefile.include | 2 + tests/pca9552-test.c | 131 ++++++++++++++++++++ 6 files changed, 427 insertions(+) create mode 100644 hw/misc/pca9552.c create mode 100644 include/hw/misc/pca9552.h create mode 100644 tests/pca9552-test.c diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 5059d134c816..d868d1095a6c 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -16,6 +16,7 @@ CONFIG_TSC2005=3Dy CONFIG_LM832X=3Dy CONFIG_TMP105=3Dy CONFIG_TMP421=3Dy +CONFIG_PCA9552=3Dy CONFIG_STELLARIS=3Dy CONFIG_STELLARIS_INPUT=3Dy CONFIG_STELLARIS_ENET=3Dy diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index e8f0a02f35af..e4e22880dbbc 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -7,6 +7,7 @@ common-obj-$(CONFIG_SGA) +=3D sga.o common-obj-$(CONFIG_ISA_TESTDEV) +=3D pc-testdev.o common-obj-$(CONFIG_PCI_TESTDEV) +=3D pci-testdev.o common-obj-$(CONFIG_EDU) +=3D edu.o +common-obj-$(CONFIG_PCA9552) +=3D pca9552.o =20 common-obj-y +=3D unimp.o =20 diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c new file mode 100644 index 000000000000..70ce6f038da2 --- /dev/null +++ b/hw/misc/pca9552.c @@ -0,0 +1,259 @@ +/* + * PCA9552 I2C LED blinker + * + * https://www.nxp.com/docs/en/application-note/AN264.pdf + * + * Copyright (c) 2017, IBM Corporation. + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/hw.h" +#include "hw/misc/pca9552.h" + +/* + * Bits [0:3] are used to address a specific register. + */ +#define PCA9552_INPUT0 0 /* read only input register 0 */ +#define PCA9552_INPUT1 1 /* read only input register 1 */ +#define PCA9552_PSC0 2 /* read/write frequency prescaler 0 */ +#define PCA9552_PWM0 3 /* read/write PWM register 0 */ +#define PCA9552_PSC1 4 /* read/write frequency prescaler 1 */ +#define PCA9552_PWM1 5 /* read/write PWM register 1 */ +#define PCA9552_LS0 6 /* read/write LED0 to LED3 selector */ +#define PCA9552_LS1 7 /* read/write LED4 to LED7 selector */ +#define PCA9552_LS2 8 /* read/write LED8 to LED11 selector */ +#define PCA9552_LS3 9 /* read/write LED12 to LED15 selector */ + +/* + * Bit [4] is used to activate the Auto-Increment option of the + * register address + */ +#define PCA9552_AUTOINC (1 << 4) + +#define PCA9552_LED_ON 0x0 +#define PCA9552_LED_OFF 0x1 +#define PCA9552_LED_PWM0 0x2 +#define PCA9552_LED_PWM1 0x3 + +static uint8_t pca9552_pin_get_config(PCA9552State *s, int pin) +{ + uint8_t reg =3D PCA9552_LS0 + (pin / 4); + uint8_t shift =3D (pin % 4) << 1; + + return extract32(s->regs[reg], shift, 2); +} + +static void pca9552_update_pin_input(PCA9552State *s) +{ + int i; + + for (i =3D 0; i < s->nr_leds; i++) { + uint8_t input_reg =3D PCA9552_INPUT0 + (i / 8); + uint8_t input_shift =3D (i % 8); + uint8_t config =3D pca9552_pin_get_config(s, i); + + switch (config) { + case PCA9552_LED_ON: + s->regs[input_reg] |=3D 1 << input_shift; + break; + case PCA9552_LED_OFF: + s->regs[input_reg] &=3D ~(1 << input_shift); + break; + case PCA9552_LED_PWM0: + case PCA9552_LED_PWM1: + /* TODO */ + default: + break; + } + } +} + +static uint8_t pca9552_read(PCA9552State *s, uint8_t reg) +{ + switch (reg) { + case PCA9552_INPUT0: + case PCA9552_INPUT1: + case PCA9552_PSC0: + case PCA9552_PWM0: + case PCA9552_PSC1: + case PCA9552_PWM1: + case PCA9552_LS0: + case PCA9552_LS1: + case PCA9552_LS2: + case PCA9552_LS3: + return s->regs[reg]; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: unexpected read to register %d= \n", + __func__, reg); + return 0xFF; + } +} + +static void pca9552_write(PCA9552State *s, uint8_t reg, uint8_t data) +{ + switch (reg) { + case PCA9552_PSC0: + case PCA9552_PWM0: + case PCA9552_PSC1: + case PCA9552_PWM1: + s->regs[reg] =3D data; + break; + + case PCA9552_LS0: + case PCA9552_LS1: + case PCA9552_LS2: + case PCA9552_LS3: + s->regs[reg] =3D data; + pca9552_update_pin_input(s); + break; + + case PCA9552_INPUT0: + case PCA9552_INPUT1: + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: unexpected write to register %= d\n", + __func__, reg); + } +} + +/* + * When Auto-Increment is on, the register address is incremented + * after each byte is sent to or received by the device. The index + * rollovers to 0 when the maximum register address is reached. + */ +static void pca9552_autoinc(PCA9552State *s) +{ + if (s->pointer !=3D 0xFF && s->pointer & PCA9552_AUTOINC) { + uint8_t reg =3D s->pointer & 0xf; + + reg =3D (reg + 1) % (s->max_reg + 1); + s->pointer =3D reg | PCA9552_AUTOINC; + } +} + +static int pca9552_recv(I2CSlave *i2c) +{ + PCA9552State *s =3D PCA9552(i2c); + uint8_t ret; + + ret =3D pca9552_read(s, s->pointer & 0xf); + + /* + * From the Specs: + * + * Important Note: When a Read sequence is initiated and the + * AI bit is set to Logic Level 1, the Read Sequence MUST + * start by a register different from 0. + * + * I don't know what should be done in this case, so throw an + * error. + */ + if (s->pointer =3D=3D PCA9552_AUTOINC) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Autoincrement read starting with register 0\n", + __func__); + } + + pca9552_autoinc(s); + + return ret; +} + +static int pca9552_send(I2CSlave *i2c, uint8_t data) +{ + PCA9552State *s =3D PCA9552(i2c); + + /* First byte sent by is the register address */ + if (s->len =3D=3D 0) { + s->pointer =3D data; + s->len++; + } else { + pca9552_write(s, s->pointer & 0xf, data); + + pca9552_autoinc(s); + } + + return 0; +} + +static int pca9552_event(I2CSlave *i2c, enum i2c_event event) +{ + PCA9552State *s =3D PCA9552(i2c); + + s->len =3D 0; + return 0; +} + +static const VMStateDescription pca9552_vmstate =3D { + .name =3D "PCA9552", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(len, PCA9552State), + VMSTATE_UINT8(pointer, PCA9552State), + VMSTATE_UINT8_ARRAY(regs, PCA9552State, PCA9552_NR_REGS), + VMSTATE_I2C_SLAVE(i2c, PCA9552State), + VMSTATE_END_OF_LIST() + } +}; + +static void pca9552_reset(DeviceState *dev) +{ + PCA9552State *s =3D PCA9552(dev); + + s->regs[PCA9552_PSC0] =3D 0xFF; + s->regs[PCA9552_PWM0] =3D 0x80; + s->regs[PCA9552_PSC1] =3D 0xFF; + s->regs[PCA9552_PWM1] =3D 0x80; + s->regs[PCA9552_LS0] =3D 0x55; /* all OFF */ + s->regs[PCA9552_LS1] =3D 0x55; + s->regs[PCA9552_LS2] =3D 0x55; + s->regs[PCA9552_LS3] =3D 0x55; + + pca9552_update_pin_input(s); + + s->pointer =3D 0xFF; + s->len =3D 0; +} + +static void pca9552_initfn(Object *obj) +{ + PCA9552State *s =3D PCA9552(obj); + + /* If support for the other PCA955X devices are implemented, these + * constant values might be part of class structure describing the + * PCA955X device + */ + s->max_reg =3D PCA9552_LS3; + s->nr_leds =3D 16; +} + +static void pca9552_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + I2CSlaveClass *k =3D I2C_SLAVE_CLASS(klass); + + k->event =3D pca9552_event; + k->recv =3D pca9552_recv; + k->send =3D pca9552_send; + dc->reset =3D pca9552_reset; + dc->vmsd =3D &pca9552_vmstate; +} + +static const TypeInfo pca9552_info =3D { + .name =3D TYPE_PCA9552, + .parent =3D TYPE_I2C_SLAVE, + .instance_init =3D pca9552_initfn, + .instance_size =3D sizeof(PCA9552State), + .class_init =3D pca9552_class_init, +}; + +static void pca9552_register_types(void) +{ + type_register_static(&pca9552_info); +} + +type_init(pca9552_register_types) diff --git a/include/hw/misc/pca9552.h b/include/hw/misc/pca9552.h new file mode 100644 index 000000000000..5df8d6407ca7 --- /dev/null +++ b/include/hw/misc/pca9552.h @@ -0,0 +1,33 @@ +/* + * PCA9552 I2C LED blinker + * + * Copyright (c) 2017, IBM Corporation. + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ +#ifndef PCA9552_H +#define PCA9552_H + +#include "hw/i2c/i2c.h" + +#define TYPE_PCA9552 "pca9552" +#define PCA9552(obj) OBJECT_CHECK(PCA9552State, (obj), TYPE_PCA9552) + + +#define PCA9552_NR_REGS 10 + +typedef struct PCA9552State { + /*< private >*/ + I2CSlave i2c; + /*< public >*/ + + uint8_t len; + uint8_t pointer; + + uint8_t regs[PCA9552_NR_REGS]; + uint8_t max_reg; + uint8_t nr_leds; +} PCA9552State; + +#endif diff --git a/tests/Makefile.include b/tests/Makefile.include index 4ca15e681703..8ac2595c8512 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -347,6 +347,7 @@ check-qtest-sparc64-y =3D tests/endianness-test$(EXESUF) check-qtest-sparc64-y +=3D tests/prom-env-test$(EXESUF) =20 check-qtest-arm-y =3D tests/tmp105-test$(EXESUF) +check-qtest-arm-y +=3D tests/pca9552-test$(EXESUF) check-qtest-arm-y +=3D tests/ds1338-test$(EXESUF) check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) gcov-files-arm-y +=3D hw/misc/tmp105.c @@ -739,6 +740,7 @@ tests/bios-tables-test$(EXESUF): tests/bios-tables-test= .o \ tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y) tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj= -y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) +tests/pca9552-test$(EXESUF): tests/pca9552-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c new file mode 100644 index 000000000000..53414452a12e --- /dev/null +++ b/tests/pca9552-test.c @@ -0,0 +1,131 @@ +/* + * QTest testcase for the PCA9552 LED blinker + * + * Copyright (c) 2017, IBM Corporation. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "libqtest.h" +#include "libqos/i2c.h" + +#define PCA9552_INPUT0 0 /* read only input register 0 */ +#define PCA9552_INPUT1 1 /* read only input register 1 */ +#define PCA9552_PSC0 2 /* read/write frequency prescaler 0 */ +#define PCA9552_PWM0 3 /* read/write PWM register 0 */ +#define PCA9552_PSC1 4 /* read/write frequency prescaler 1 */ +#define PCA9552_PWM1 5 /* read/write PWM register 1 */ +#define PCA9552_LS0 6 /* read/write LED0 to LED3 selector */ +#define PCA9552_LS1 7 /* read/write LED4 to LED7 selector */ +#define PCA9552_LS2 8 /* read/write LED8 to LED11 selector */ +#define PCA9552_LS3 9 /* read/write LED12 to LED15 selector */ + +#define PCA9552_AUTOINC (1 << 4) + + +#define OMAP2_I2C_1_BASE 0x48070000 + +#define PCA9552_TEST_ID "pca9552-test" +#define PCA9552_TEST_ADDR 0x60 + +static I2CAdapter *i2c; + +static uint8_t pca9552_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg) +{ + uint8_t resp[1]; + i2c_send(i2c, addr, ®, 1); + i2c_recv(i2c, addr, resp, 1); + return resp[0]; +} + +static void pca9552_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint8_t value) +{ + uint8_t cmd[2]; + uint8_t resp[1]; + + cmd[0] =3D reg; + cmd[1] =3D value; + i2c_send(i2c, addr, cmd, 2); + i2c_recv(i2c, addr, resp, 1); + g_assert_cmphex(resp[0], =3D=3D, cmd[1]); +} + +static void receive_autoinc(void) +{ + uint8_t resp; + uint8_t reg =3D PCA9552_LS0 | PCA9552_AUTOINC; + + i2c_send(i2c, PCA9552_TEST_ADDR, ®, 1); + + /* PCA9552_LS0 */ + i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + g_assert_cmphex(resp, =3D=3D, 0x54); + + /* PCA9552_LS1 */ + i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + g_assert_cmphex(resp, =3D=3D, 0x55); + + /* PCA9552_LS2 */ + i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + g_assert_cmphex(resp, =3D=3D, 0x55); + + /* PCA9552_LS3 */ + i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + g_assert_cmphex(resp, =3D=3D, 0x54); +} + +static void send_and_receive(void) +{ + uint8_t value; + + value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); + g_assert_cmphex(value, =3D=3D, 0x55); + + value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); + g_assert_cmphex(value, =3D=3D, 0x0); + + /* Switch on LED 0 */ + pca9552_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54); + value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); + g_assert_cmphex(value, =3D=3D, 0x54); + + value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); + g_assert_cmphex(value, =3D=3D, 0x01); + + /* Switch on LED 12 */ + pca9552_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54); + value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3); + g_assert_cmphex(value, =3D=3D, 0x54); + + value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT1); + g_assert_cmphex(value, =3D=3D, 0x10); +} + +int main(int argc, char **argv) +{ + QTestState *s =3D NULL; + int ret; + + g_test_init(&argc, &argv, NULL); + + s =3D qtest_start("-machine n800 " + "-device pca9552,bus=3Di2c-bus.0,id=3D" PCA9552_TEST_ID + ",address=3D0x60"); + i2c =3D omap_i2c_create(OMAP2_I2C_1_BASE); + + qtest_add_func("/pca9552/tx-rx", send_and_receive); + qtest_add_func("/pca9552/rx-autoinc", receive_autoinc); + + ret =3D g_test_run(); + + if (s) { + qtest_quit(s); + } + g_free(i2c); + + return ret; +} --=20 2.13.6 From nobody Fri May 3 01:13:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508407823241493.02100324262585; Thu, 19 Oct 2017 03:10:23 -0700 (PDT) Received: from localhost ([::1]:48480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57mN-0007nh-Hg for importer@patchew.org; Thu, 19 Oct 2017 06:10:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e57hc-0003Sv-Hp for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e57hZ-0000Nu-SH for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:24 -0400 Received: from 20.mo5.mail-out.ovh.net ([91.121.55.239]:58866) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e57hZ-0000MZ-KL for qemu-devel@nongnu.org; Thu, 19 Oct 2017 06:05:21 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id D8280145684 for ; Thu, 19 Oct 2017 12:05:18 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-2231-173.w90-76.abo.wanadoo.fr [90.76.52.173]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id A73CA80099; Thu, 19 Oct 2017 12:05:11 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 19 Oct 2017 12:04:10 +0200 Message-Id: <20171019100410.26239-9-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171019100410.26239-1-clg@kaod.org> References: <20171019100410.26239-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8709398732239309585 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrudekgddviecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 91.121.55.239 Subject: [Qemu-devel] [PATCH v4 8/8] aspeed: add the pc9552 chips to the witherspoon machine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The pca9552 LED blinkers on the Witherspoon machine are used for leds but also as GPIOs to control fans and GPUs. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Andrew Jeffery --- hw/arm/aspeed.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index 2e08eb49f443..217461081085 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -400,6 +400,8 @@ static void witherspoon_bmc_i2c_init(AspeedBoardState *= bmc) AspeedSoCState *soc =3D &bmc->soc; uint8_t *eeprom_buf =3D g_malloc0(8 * 1024); =20 + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), "pca9552", = 0x60); + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "tmp423", 0= x4c); i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 5), "tmp423", 0= x4c); =20 @@ -412,6 +414,8 @@ static void witherspoon_bmc_i2c_init(AspeedBoardState *= bmc) =20 smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), 0x51, eeprom_buf); + i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "pca9552", + 0x60); } =20 static void witherspoon_bmc_init(MachineState *machine) --=20 2.13.6