From patchwork Thu Nov 7 19:54:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13867050 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6F89D5D688 for ; Thu, 7 Nov 2024 19:56:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t98ax-0001Vs-Sg; Thu, 07 Nov 2024 14:55:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3EhstZwYKCj0shstrqfnnfkd.bnlpdlt-cdudkmnmfmt.nqf@flex--titusr.bounces.google.com>) id 1t98av-0001Tk-F6 for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:05 -0500 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3EhstZwYKCj0shstrqfnnfkd.bnlpdlt-cdudkmnmfmt.nqf@flex--titusr.bounces.google.com>) id 1t98as-0003KH-TQ for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:05 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6ea258fe4b6so25991107b3.1 for ; Thu, 07 Nov 2024 11:54:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731009299; x=1731614099; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3Z/XclSmqT8Xhgqma+tYcLYhVDFwTbVxhxPc4Sd2yjI=; b=ipc96J9GZq6QWQsckbNsetr6naEEjQigxVOuz7XCBliSo/UT9yHMg/k+oSmB9R2JEf 3QmUSn8bgMw/k2UiZQbbO55srT2vMWfpJLYnK0//mR/raGdyx908XIXi0hrNqttvxHwc KheWPVoRS/sKdjXxb3hwj3K5UQjCBrJ4gTINDcCuoreqz/nTBJfUNTlGEzpsm7+DpBC4 bA+ttdBe2bMU/HRmgNgciroWrBzdlhAOvHJSgMQS1YHwujW5JZKWLlPcocto4t3JSWNm Ikl/sWa2LXVYbW33RMU3+r5j85OHB/Gdix9SXStLw7dF+dWaYVlsgcdrrxRopou48k3r 40Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731009299; x=1731614099; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3Z/XclSmqT8Xhgqma+tYcLYhVDFwTbVxhxPc4Sd2yjI=; b=flQKYCuuWh2r6twVBFs8mbl01EbLt8sUy/SxgVmajqFAGqWuPO7BA0bcuQUj0qvyNZ 23nzOInty8hQr25Apb65sfQ/XCWZv0Eark/vLdwODlMu1VtK3boxlL7xXqU5Rj5eSZT7 cbOK8fD/VZxWVLCSR7PIIoWtRXCeGNbim/eWnfQAMEsFrwNWNcXauqJuzQP/20F8sXNm WvQQ9MOPuY0y6NORKnqPeWmnotreHTaD2aASjOCtVUFBMIjqUEA3IHpadGRNcSTgKavb UohuMIPfyZGkFqYq5lMwiPQdl37D2DoqeYXoj6KDQmV51zdXNRVNnOYXbN9jmB3TAJnC 17bw== X-Forwarded-Encrypted: i=1; AJvYcCWw6lAy4Pq0ix2k/9w5AYdO0uiNu2Eg5HrXNPrFEUjrKDr9X0fkAhSTNuF9aogVjydIpbisYiDSvy/I@nongnu.org X-Gm-Message-State: AOJu0YybEafvi/XtvZbU386hO53wT0bZs7WU3UlxTjxZ+pdFockg48iT QajXrv5+Y8+rVwm/pSQmZz+4u8zUDLIFKmgcJtO1IX+8lMTEA6sjl9qkc/zza3RO558T2wTwwOz 0mg== X-Google-Smtp-Source: AGHT+IEoKLOtlze2ZJ2kJ2E+JQup5sz1gQfCuIsdgKc4JKTWxtcEwo2hpMqv8+7yB3w6Ijy1AVirAR//sig= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:dc:567e:c0a8:e14]) (user=titusr job=sendgmr) by 2002:a05:690c:887:b0:6b2:6cd4:7f9a with SMTP id 00721157ae682-6eaddff31bcmr1577b3.8.1731009298680; Thu, 07 Nov 2024 11:54:58 -0800 (PST) Date: Thu, 7 Nov 2024 19:54:48 +0000 In-Reply-To: <20241107195453.2684138-1-titusr@google.com> Mime-Version: 1.0 References: <20241107195453.2684138-1-titusr@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107195453.2684138-2-titusr@google.com> Subject: [PATCH 1/6] bitops.h: add deposit16 function From: Titus Rwantare To: peter.maydell@linaro.org, minyard@acm.org, clg@redhat.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, philmd@linaro.org, venture@google.com, wuhaotsh@google.com, milesg@linux.vnet.ibm.com, Titus Rwantare Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3EhstZwYKCj0shstrqfnnfkd.bnlpdlt-cdudkmnmfmt.nqf@flex--titusr.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Makes it more explicit that 16 bit values are being used Signed-off-by: Titus Rwantare Reviewed-by: Glenn Miles --- include/qemu/bitops.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 2c0a2fe751..05179e3ded 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -459,6 +459,32 @@ static inline int64_t sextract64(uint64_t value, int start, int length) return ((int64_t)(value << (64 - length - start))) >> (64 - length); } +/** + * deposit16: + * @value: initial value to insert bit field into + * @start: the lowest bit in the bit field (numbered from 0) + * @length: the length of the bit field + * @fieldval: the value to insert into the bit field + * + * Deposit @fieldval into the 16 bit @value at the bit field specified + * by the @start and @length parameters, and return the modified + * @value. Bits of @value outside the bit field are not modified. + * Bits of @fieldval above the least significant @length bits are + * ignored. The bit field must lie entirely within the 16 bit word. + * It is valid to request that all 16 bits are modified (ie @length + * 16 and @start 0). + * + * Returns: the modified @value. + */ +static inline uint16_t deposit16(uint16_t value, int start, int length, + uint16_t fieldval) +{ + uint16_t mask; + assert(start >= 0 && length > 0 && length <= 16 - start); + mask = (~0U >> (16 - length)) << start; + return (value & ~mask) | ((fieldval << start) & mask); +} + /** * deposit32: * @value: initial value to insert bit field into From patchwork Thu Nov 7 19:54:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13867054 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DA55CD5D683 for ; Thu, 7 Nov 2024 19:56:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t98b0-0001ZI-NE; Thu, 07 Nov 2024 14:55:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3ExstZwYKCj4ynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1t98av-0001UJ-Tk for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:05 -0500 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ExstZwYKCj4ynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1t98ar-0003KR-C1 for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:05 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6ea86f1df79so25569617b3.1 for ; Thu, 07 Nov 2024 11:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731009300; x=1731614100; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=fh6EVdMWkSlgfhCNmuALnMqxPtdCp57WS1G6iNMbs3U=; b=iI02uI9q9T8o4tDYM/Rvh3pHbwtUKed0cv2/YQ8DlM3WDKcsIqLpdvlJyPA8bq6qeV RjJg+D/zBoAlPjEupN8uhHJxd1q+ORwDdJNB2olQm1qhJTKByxqNrgWIgoGnXTYkIA4r BmgenJPzGll6X/HBAgmmQVeCrf95tE0A49Fyue1lOex5CueDrvTullfBTVpGKtrNL/c4 5ZEJ9fOSeQ8d3KL1qGOiFaxeZnuhuFI69rgbhdsdemwOgrm9L6d/8gABaGpeseUH4MBP XSHwIJvXC+CI5vBNwIPXp42n565X5pwSrEhQ+He5E4wSYE6Jglfnh1PAeKhOENxsC6wt v/+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731009300; x=1731614100; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=fh6EVdMWkSlgfhCNmuALnMqxPtdCp57WS1G6iNMbs3U=; b=Uf+xu+h86JYyj080aO/tuageNhz33p4YxBn37J7VCpkUAKvk+21SEl9zXhK81Y6x4W e61DjvC12WcfUB/T1NeBs3KRTAIVRViCUBDtoVXdx0W/lXRggjpxhYuAYHXp+eyF2sd6 sUbrL5x/jmiyD6o/g+3TLytcCH9IuN2I1rwuw2FNdtZLhUkIwPPIjEdok31+13V2n6ly 5UKk2vxLz4d4V1JS8cuMqNvAtO0GRR/BZJUN7lHk7LFGARolX4GKtCsNV5pllQh4ZNLw GkHWK44bYY6E+wbI90P/CXTNewtVaMSglhdYS1IjE0EYzMOidrKOPCRPi0PEr6s/icCj ypUg== X-Forwarded-Encrypted: i=1; AJvYcCUzMtppCOBFaHYLN9oibFR9SzurmFey9ZnVNi2KQn4jvl7TIuHi1bnxLMtGBM+hnUJOqiH6NxSaxGE7@nongnu.org X-Gm-Message-State: AOJu0YyfKKZ31YZ9xhKlTiMq6yXR074amiAeZv6cvJsgdVvj2s9lvggh dIMp9rQgU3TJ5WPoTxjjlMweIgM0KKPj48Ucnb4GG+57fTGa2MJANYRrL6Q6oG3GpXrA/Qzqh1X K5A== X-Google-Smtp-Source: AGHT+IGVwOD+toJRIVcoghaApbc/ubhgXalVgYcg2t2Il/0IXMePlBEMfXj/brEhOcXS/JIcGEecMVyOSBw= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:dc:567e:c0a8:e14]) (user=titusr job=sendgmr) by 2002:a05:690c:60ca:b0:6e6:38:8567 with SMTP id 00721157ae682-6eaddfe6275mr1027b3.8.1731009299737; Thu, 07 Nov 2024 11:54:59 -0800 (PST) Date: Thu, 7 Nov 2024 19:54:49 +0000 In-Reply-To: <20241107195453.2684138-1-titusr@google.com> Mime-Version: 1.0 References: <20241107195453.2684138-1-titusr@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107195453.2684138-3-titusr@google.com> Subject: [PATCH 2/6] hw/gpio: add PCA953x i2c GPIO expanders From: Titus Rwantare To: peter.maydell@linaro.org, minyard@acm.org, clg@redhat.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, philmd@linaro.org, venture@google.com, wuhaotsh@google.com, milesg@linux.vnet.ibm.com, Titus Rwantare Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3ExstZwYKCj4ynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The PCA6416 is an i2c device with 16 GPIO pins, the PCA9538 has 8 pins. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Hao Wu Signed-off-by: Titus Rwantare --- hw/gpio/Kconfig | 5 + hw/gpio/meson.build | 1 + hw/gpio/pca_i2c_gpio.c | 391 ++++++++++++++++++++++++++++++++ hw/gpio/trace-events | 5 + include/hw/gpio/pca_i2c_gpio.h | 68 ++++++ tests/qtest/meson.build | 1 + tests/qtest/pca_i2c_gpio-test.c | 188 +++++++++++++++ 7 files changed, 659 insertions(+) create mode 100644 hw/gpio/pca_i2c_gpio.c create mode 100644 include/hw/gpio/pca_i2c_gpio.h create mode 100644 tests/qtest/pca_i2c_gpio-test.c diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig index c423e10f59..fde1155424 100644 --- a/hw/gpio/Kconfig +++ b/hw/gpio/Kconfig @@ -13,6 +13,11 @@ config GPIO_PWR config SIFIVE_GPIO bool +config PCA_I2C_GPIO + bool + depends on I2C + default y if I2C_DEVICES + config STM32L4X5_GPIO bool diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build index 74840619c0..51f3ba7fc5 100644 --- a/hw/gpio/meson.build +++ b/hw/gpio/meson.build @@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_PCA_I2C_GPIO', if_true: files('pca_i2c_gpio.c')) diff --git a/hw/gpio/pca_i2c_gpio.c b/hw/gpio/pca_i2c_gpio.c new file mode 100644 index 0000000000..2486c620e3 --- /dev/null +++ b/hw/gpio/pca_i2c_gpio.c @@ -0,0 +1,391 @@ +/* + * NXP PCA I2C GPIO Expanders + * + * Low-voltage translating 16-bit I2C/SMBus GPIO expander with interrupt output, + * reset, and configuration registers + * + * Datasheet: https://www.nxp.com/docs/en/data-sheet/PCA6416A.pdf + * https://www.ti.com/lit/ds/symlink/pca9538.pdf + * + * Copyright 2024 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * To assert some input pins before boot, use the following in the board file of + * the machine: + * object_property_set_uint(Object *obj, const char *name, + * uint64_t value, Error **errp); + * specifying name as "gpio_config" and the value as a bitfield of the inputs + * e.g. for the pca6416, a value of 0xFFF0, configures pins 0-3 as outputs and + * 4-15 as inputs. + * Then using name "gpio_input" with value "0x0F00" would raise GPIOs 8-11. + * + * This value can also be set at runtime through qmp externally, or by + * writing to the config register using i2c. The guest driver should generally + * control the config register, but exposing it via qmp allows external testing. + * + */ + +#include "qemu/osdep.h" +#include "hw/gpio/pca_i2c_gpio.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "qapi/visitor.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/bitops.h" +#include "trace.h" + +/* + * compare new_output to curr_output and update irq to match new_output + * + * The Input port registers (registers 0 and 1) reflect the incoming logic + * levels of the pins, regardless of whether the pin is defined as an input or + * an output by the Configuration register. + */ +static void pca_i2c_update_irqs(PCAGPIOState *ps) +{ + PCAGPIOClass *pc = PCA_I2C_GPIO_GET_CLASS(ps); + uint16_t out_diff = ps->new_output ^ ps->curr_output; + uint16_t in_diff = ps->new_input ^ ps->curr_input; + uint16_t mask, pin_i; + + if (in_diff || out_diff) { + for (int i = 0; i < pc->num_pins; i++) { + mask = BIT(i); + /* pin must be configured as an output to be set here */ + if (out_diff & ~ps->config & mask) { + pin_i = mask & ps->new_output; + qemu_set_irq(ps->output[i], pin_i > 0); + ps->curr_output &= ~mask; + ps->curr_output |= pin_i; + } + + if (in_diff & mask) { + ps->curr_input &= ~mask; + ps->curr_input |= mask & ps->new_input; + } + } + /* make diff = 0 */ + ps->new_input = ps->curr_input; + } +} + +static void pca_i2c_irq_handler(void *opaque, int n, int level) +{ + PCAGPIOState *ps = opaque; + PCAGPIOClass *pc = PCA_I2C_GPIO_GET_CLASS(opaque); + uint16_t mask = BIT(n); + + g_assert(n < pc->num_pins); + g_assert(n >= 0); + + ps->new_input &= ~mask; + + if (level > 0) { + ps->new_input |= BIT(n); + } + + pca_i2c_update_irqs(ps); +} + +/* slave to master */ +static uint8_t _pca953x_recv(I2CSlave *i2c, uint32_t shift) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(i2c); + uint8_t data; + + switch (ps->command) { + case PCA953x_INPUT_PORT: + data = extract16(ps->curr_input, shift, 8); + break; + /* + * i2c reads to the output registers reflect the values written + * NOT the actual values of the gpios + */ + case PCA953x_OUTPUT_PORT: + data = extract16(ps->new_output, shift, 8); + break; + + case PCA953x_POLARITY_INVERSION_PORT: + data = extract16(ps->polarity_inv, shift, 8); + break; + + case PCA953x_CONFIGURATION_PORT: + data = extract16(ps->config, shift, 8); + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: reading from unsupported register 0x%02x", + __func__, ps->command); + data = 0xFF; + break; + } + + trace_pca_i2c_recv(DEVICE(ps)->canonical_path, ps->command, shift, data); + return data; +} + +static uint8_t pca6416_recv(I2CSlave *i2c) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(i2c); + uint32_t shift = ps->command & 1 ? 8 : 0; + + /* Transform command into 4 port equivalent */ + ps->command = ps->command >> 1; + + return _pca953x_recv(i2c, shift); +} + +static uint8_t pca953x_recv(I2CSlave *i2c) +{ + return _pca953x_recv(i2c, 0); +} + +/* master to slave */ +static int _pca953x_send(I2CSlave *i2c, uint32_t shift, uint8_t data) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(i2c); + + if (ps->i2c_cmd) { + ps->command = data; + ps->i2c_cmd = false; + return 0; + } + + trace_pca_i2c_send(DEVICE(ps)->canonical_path, ps->command, shift, data); + + switch (ps->command) { + case PCA953x_INPUT_PORT: + qemu_log_mask(LOG_GUEST_ERROR, "%s: writing to read only reg: 0x%02x", + __func__, ps->command); + break; + case PCA953x_OUTPUT_PORT: + ps->new_output = deposit16(ps->new_output, shift, 8, data); + break; + + case PCA953x_POLARITY_INVERSION_PORT: + ps->polarity_inv = deposit16(ps->polarity_inv, shift, 8, data); + break; + + case PCA953x_CONFIGURATION_PORT: + ps->config = deposit16(ps->config, shift, 8, data); + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: writing to unsupported register\n", + __func__); + return -1; + } + + pca_i2c_update_irqs(ps); + return 0; +} + +static int pca6416_send(I2CSlave *i2c, uint8_t data) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(i2c); + uint32_t shift = ps->command & 1 ? 8 : 0; + + /* Transform command into 4 port equivalent */ + ps->command = ps->command >> 1; + + return _pca953x_send(i2c, shift, data); +} + +static int pca953x_send(I2CSlave *i2c, uint8_t data) +{ + return _pca953x_send(i2c, 0, data); +} + +static int pca_i2c_event(I2CSlave *i2c, enum i2c_event event) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(i2c); + + switch (event) { + case I2C_START_RECV: + trace_pca_i2c_event(DEVICE(ps)->canonical_path, "START_RECV"); + break; + + case I2C_START_SEND: + trace_pca_i2c_event(DEVICE(ps)->canonical_path, "START_SEND"); + ps->i2c_cmd = true; + break; + + case I2C_FINISH: + trace_pca_i2c_event(DEVICE(ps)->canonical_path, "FINISH"); + break; + + case I2C_NACK: + trace_pca_i2c_event(DEVICE(ps)->canonical_path, "NACK"); + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: unknown event 0x%x\n", + DEVICE(ps)->canonical_path, __func__, event); + return -1; + } + + return 0; +} + +static void pca_i2c_config_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + visit_type_uint16(v, name, &ps->config, errp); +} + +static void pca_i2c_config_set(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + if (!visit_type_uint16(v, name, &ps->config, errp)) { + return; + } + pca_i2c_update_irqs(ps); +} + +static void pca_i2c_input_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + visit_type_uint16(v, name, &ps->curr_input, errp); +} + +static void pca_i2c_input_set(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + if (!visit_type_uint16(v, name, &ps->new_input, errp)) { + return; + } + pca_i2c_update_irqs(ps); +} + +static void pca_i2c_output_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + visit_type_uint16(v, name, &ps->curr_output, errp); +} + +static void pca_i2c_output_set(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + if (!visit_type_uint16(v, name, &ps->new_output, errp)) { + return; + } + pca_i2c_update_irqs(ps); +} + +static void pca_i2c_enter_reset(Object *obj, ResetType type) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + + ps->polarity_inv = 0; + ps->config = 0; + ps->new_input = 0; + ps->new_output = 0; + ps->command = 0; + + pca_i2c_update_irqs(ps); +} + +static const VMStateDescription vmstate_pca_i2c_gpio = { + .name = TYPE_PCA_I2C_GPIO, + .version_id = 0, + .minimum_version_id = 0, + .fields = (VMStateField[]) { + VMSTATE_I2C_SLAVE(parent, PCAGPIOState), + VMSTATE_UINT16(polarity_inv, PCAGPIOState), + VMSTATE_UINT16(config, PCAGPIOState), + VMSTATE_UINT16(curr_input, PCAGPIOState), + VMSTATE_UINT16(curr_output, PCAGPIOState), + VMSTATE_END_OF_LIST() + } +}; + +static void pca6416_gpio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); + PCAGPIOClass *pc = PCA_I2C_GPIO_CLASS(klass); + + dc->desc = "PCA6416 16-bit I/O expander"; + pc->num_pins = PCA6416_NUM_PINS; + + k->recv = pca6416_recv; + k->send = pca6416_send; +} + +static void pca9538_gpio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); + PCAGPIOClass *pc = PCA_I2C_GPIO_CLASS(klass); + + dc->desc = "PCA9538 8-bit I/O expander"; + pc->num_pins = PCA9538_NUM_PINS; + + k->recv = pca953x_recv; + k->send = pca953x_send; +} + +static void pca_i2c_gpio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); + + dc->vmsd = &vmstate_pca_i2c_gpio; + rc->phases.enter = pca_i2c_enter_reset; + k->event = pca_i2c_event; +} + +static void pca_i2c_gpio_init(Object *obj) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + PCAGPIOClass *pc = PCA_I2C_GPIO_GET_CLASS(obj); + DeviceState *dev = DEVICE(obj); + + object_property_add(obj, "gpio_input", "uint16", + pca_i2c_input_get, + pca_i2c_input_set, NULL, NULL); + object_property_add(obj, "gpio_output", "uint16", + pca_i2c_output_get, + pca_i2c_output_set, NULL, NULL); + object_property_add(obj, "gpio_config", "uint16", + pca_i2c_config_get, + pca_i2c_config_set, NULL, NULL); + qdev_init_gpio_in(dev, pca_i2c_irq_handler, pc->num_pins); + qdev_init_gpio_out(dev, ps->output, pc->num_pins); +} + +static const TypeInfo pca_gpio_types[] = { + { + .name = TYPE_PCA_I2C_GPIO, + .parent = TYPE_I2C_SLAVE, + .instance_size = sizeof(PCAGPIOState), + .instance_init = pca_i2c_gpio_init, + .class_size = sizeof(PCAGPIOClass), + .class_init = pca_i2c_gpio_class_init, + .abstract = true, + }, + { + .name = TYPE_PCA6416_GPIO, + .parent = TYPE_PCA_I2C_GPIO, + .class_init = pca6416_gpio_class_init, + }, + { + .name = TYPE_PCA9538_GPIO, + .parent = TYPE_PCA_I2C_GPIO, + .class_init = pca9538_gpio_class_init, + }, +}; + +DEFINE_TYPES(pca_gpio_types); diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events index b91cc7e9a4..722fbdd54e 100644 --- a/hw/gpio/trace-events +++ b/hw/gpio/trace-events @@ -41,3 +41,8 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" + +# pca_i2c_gpio.c +pca_i2c_event(const char *id, const char *event) "%s: %s" +pca_i2c_recv(const char *id, uint8_t cmd, uint32_t shift, uint8_t data) "%s cmd: 0x%" PRIx8 "shift: %" PRIi32 " data 0x%" PRIx8 +pca_i2c_send(const char *id, uint8_t cmd, uint32_t shift, uint8_t data) "%s cmd: 0x%" PRIx8 "shift: %" PRIi32 " data 0x%" PRIx8 diff --git a/include/hw/gpio/pca_i2c_gpio.h b/include/hw/gpio/pca_i2c_gpio.h new file mode 100644 index 0000000000..61e5853c24 --- /dev/null +++ b/include/hw/gpio/pca_i2c_gpio.h @@ -0,0 +1,68 @@ +/* + * NXP PCA I2C GPIO Expanders + * Low-voltage translating 16-bit I2C/SMBus GPIO expander with interrupt output, + * reset, and configuration registers + * + * Datasheet: https://www.nxp.com/docs/en/data-sheet/PCA6416A.pdf + * https://www.ti.com/lit/ds/symlink/pca9538.pdf + * + * Note: Polarity inversion emulation not implemented + * + * Copyright 2024 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef PCA_I2C_GPIO_H +#define PCA_I2C_GPIO_H + +#include "hw/i2c/i2c.h" +#include "qom/object.h" + +#define PCA_I2C_MAX_PINS 16 +#define PCA6416_NUM_PINS 16 +#define PCA9538_NUM_PINS 8 + +typedef struct PCAGPIOClass { + I2CSlaveClass parent; + + uint8_t num_pins; +} PCAGPIOClass; + +typedef struct PCAGPIOState { + I2CSlave parent; + + uint16_t polarity_inv; + uint16_t config; + + /* the values of the gpio pins are mirrored in these integers */ + uint16_t curr_input; + uint16_t curr_output; + uint16_t new_input; + uint16_t new_output; + + /* + * Note that these outputs need to be consumed by some other input + * to be useful, qemu ignores writes to disconnected gpio pins + */ + qemu_irq output[PCA_I2C_MAX_PINS]; + + /* i2c transaction info */ + uint8_t command; + bool i2c_cmd; + +} PCAGPIOState; + +#define TYPE_PCA_I2C_GPIO "pca_i2c_gpio" +OBJECT_DECLARE_TYPE(PCAGPIOState, PCAGPIOClass, PCA_I2C_GPIO) + +#define PCA953x_INPUT_PORT 0x00 /* read */ +#define PCA953x_OUTPUT_PORT 0x01 /* read/write */ +#define PCA953x_POLARITY_INVERSION_PORT 0x02 /* read/write */ +#define PCA953x_CONFIGURATION_PORT 0x03 /* read/write */ + +#define PCA_I2C_CONFIG_DEFAULT 0 + +#define TYPE_PCA6416_GPIO "pca6416" +#define TYPE_PCA9538_GPIO "pca9538" + +#endif diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index aa93e98418..8a02a06a06 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -291,6 +291,7 @@ qos_test_ss.add( 'ne2000-test.c', 'tulip-test.c', 'nvme-test.c', + 'pca_i2c_gpio-test.c', 'pca9552-test.c', 'pci-test.c', 'pcnet-test.c', diff --git a/tests/qtest/pca_i2c_gpio-test.c b/tests/qtest/pca_i2c_gpio-test.c new file mode 100644 index 0000000000..2bb4c6a664 --- /dev/null +++ b/tests/qtest/pca_i2c_gpio-test.c @@ -0,0 +1,188 @@ +/* + * QTest for PCA I2C GPIO expanders + * + * Copyright 2021 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/gpio/pca_i2c_gpio.h" +#include "libqtest-single.h" +#include "libqos/i2c.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qnum.h" +#include "qemu/bitops.h" + + +#define PCA6416_INPUT_PORT_0 0x00 /* read */ +#define PCA6416_INPUT_PORT_1 0x01 /* read */ +#define PCA6416_OUTPUT_PORT_0 0x02 /* read/write */ +#define PCA6416_OUTPUT_PORT_1 0x03 /* read/write */ +#define PCA6416_POLARITY_INVERSION_PORT_0 0x04 /* read/write */ +#define PCA6416_POLARITY_INVERSION_PORT_1 0x05 /* read/write */ +#define PCA6416_CONFIGURATION_PORT_0 0x06 /* read/write */ +#define PCA6416_CONFIGURATION_PORT_1 0x07 /* read/write */ + + +#define TEST_ID "pca_i2c_gpio-test" +#define PCA_CONFIG_BYTE 0x55 +#define PCA_CONFIG_BYTE_UPPER 0xAA +#define PCA_CONFIG_WORD 0xAA55 + +static uint16_t qmp_pca_gpio_get(const char *id, const char *property) +{ + QDict *response; + uint16_t ret; + response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, " + "'property': %s } }", id, property); + g_assert(qdict_haskey(response, "return")); + ret = qnum_get_uint(qobject_to(QNum, qdict_get(response, "return"))); + qobject_unref(response); + return ret; +} + +static void qmp_pca_gpio_set(const char *id, const char *property, + uint16_t value) +{ + QDict *response; + + response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, " + "'property': %s, 'value': %u } }", + id, property, value); + g_assert(qdict_haskey(response, "return")); + qobject_unref(response); +} + +static void test_set_input(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev = (QI2CDevice *)obj; + uint8_t value; + uint16_t qmp_value; + /* configure pins to be inputs */ + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_0, 0xFF); + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_1, 0xFF); + + qmp_pca_gpio_set(TEST_ID, "gpio_input", 0xAAAA); + value = i2c_get8(i2cdev, PCA6416_INPUT_PORT_0); + g_assert_cmphex(value, ==, 0xAA); + value = i2c_get8(i2cdev, PCA6416_INPUT_PORT_1); + g_assert_cmphex(value, ==, 0xAA); + + qmp_value = qmp_pca_gpio_get(TEST_ID, "gpio_input"); + g_assert_cmphex(qmp_value, ==, 0xAAAA); +} +static void test_config(void *obj, void *data, QGuestAllocator *alloc) +{ + + QI2CDevice *i2cdev = (QI2CDevice *)obj; + uint8_t value; + uint16_t qmp_value; + /* configure half the pins to be inputs */ + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_0, PCA_CONFIG_BYTE); + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_1, PCA_CONFIG_BYTE_UPPER); + value = i2c_get8(i2cdev, PCA6416_CONFIGURATION_PORT_0); + g_assert_cmphex(value, ==, PCA_CONFIG_BYTE); + + value = i2c_get8(i2cdev, PCA6416_CONFIGURATION_PORT_1); + g_assert_cmphex(value, ==, PCA_CONFIG_BYTE_UPPER); + + /* the pins that match the config should be set, the rest are undef */ + qmp_pca_gpio_set(TEST_ID, "gpio_input", 0xFFFF); + value = i2c_get8(i2cdev, PCA6416_INPUT_PORT_0); + g_assert_cmphex(value & PCA_CONFIG_BYTE, ==, 0x55); + value = i2c_get8(i2cdev, PCA6416_INPUT_PORT_1); + g_assert_cmphex(value & PCA_CONFIG_BYTE_UPPER, ==, 0xAA); + qmp_value = qmp_pca_gpio_get(TEST_ID, "gpio_input"); + g_assert_cmphex(qmp_value & PCA_CONFIG_WORD, ==, 0xAA55); + + /* + * i2c will return the value written to the output register, not the values + * of the output pins, so we check only the configured pins + */ + qmp_pca_gpio_set(TEST_ID, "gpio_output", 0xFFFF); + value = i2c_get8(i2cdev, PCA6416_OUTPUT_PORT_0); + g_assert_cmphex(value & ~PCA_CONFIG_BYTE, ==, 0xAA); + value = i2c_get8(i2cdev, PCA6416_OUTPUT_PORT_1); + g_assert_cmphex(value & ~PCA_CONFIG_BYTE_UPPER, ==, 0x55); + + qmp_value = qmp_pca_gpio_get(TEST_ID, "gpio_output"); + g_assert_cmphex(qmp_value & ~PCA_CONFIG_WORD, ==, 0x55AA); +} + +static void test_set_output(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev = (QI2CDevice *)obj; + uint8_t value; + uint16_t qmp_value; + /* configure pins to be outputs */ + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_0, 0); + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_1, 0); + + qmp_pca_gpio_set(TEST_ID, "gpio_output", 0xBB55); + value = i2c_get8(i2cdev, PCA6416_OUTPUT_PORT_0); + g_assert_cmphex(value, ==, 0x55); + value = i2c_get8(i2cdev, PCA6416_OUTPUT_PORT_1); + g_assert_cmphex(value, ==, 0xBB); + + qmp_value = qmp_pca_gpio_get(TEST_ID, "gpio_output"); + g_assert_cmphex(qmp_value, ==, 0xBB55); +} + +static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev = (QI2CDevice *)obj; + uint8_t value; + + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_0, 0xFF); + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_1, 0xFF); + i2c_set8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_0, 0); + i2c_set8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_1, 0); + + value = i2c_get8(i2cdev, PCA6416_CONFIGURATION_PORT_0); + g_assert_cmphex(value, ==, 0xFF); + + value = i2c_get8(i2cdev, PCA6416_CONFIGURATION_PORT_1); + g_assert_cmphex(value, ==, 0xFF); + + value = i2c_get8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_0); + g_assert_cmphex(value, ==, 0); + + value = i2c_get8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_1); + g_assert_cmphex(value, ==, 0); + + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_0, 0xAB); + value = i2c_get8(i2cdev, PCA6416_CONFIGURATION_PORT_0); + g_assert_cmphex(value, ==, 0xAB); + + i2c_set8(i2cdev, PCA6416_CONFIGURATION_PORT_1, 0xBC); + value = i2c_get8(i2cdev, PCA6416_CONFIGURATION_PORT_1); + g_assert_cmphex(value, ==, 0xBC); + + i2c_set8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_0, 0xAB); + value = i2c_get8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_0); + g_assert_cmphex(value, ==, 0xAB); + + i2c_set8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_1, 0x7C); + value = i2c_get8(i2cdev, PCA6416_POLARITY_INVERSION_PORT_1); + g_assert_cmphex(value, ==, 0x7C); + +} + +static void pca_i2c_gpio_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "id=" TEST_ID ",address=0x78" + }; + add_qi2c_address(&opts, &(QI2CAddress) { 0x78 }); + g_test_set_nonfatal_assertions(); + + qos_node_create_driver("pca6416", i2c_device_create); + qos_node_consumes("pca6416", "i2c-bus", &opts); + + qos_add_test("tx-rx", "pca6416", test_tx_rx, NULL); + qos_add_test("set_output_gpio", "pca6416", test_set_output, NULL); + qos_add_test("set_input_gpio", "pca6416", test_set_input, NULL); + qos_add_test("follow_gpio_config", "pca6416", test_config, NULL); +} +libqos_init(pca_i2c_gpio_register_nodes); From patchwork Thu Nov 7 19:54:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13867053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84A37D5D687 for ; Thu, 7 Nov 2024 19:56:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t98b3-0001cJ-VA; Thu, 07 Nov 2024 14:55:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3FBstZwYKCj8ujuvtshpphmf.dpnrfnv-efwfmopohov.psh@flex--titusr.bounces.google.com>) id 1t98ax-0001VD-18 for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:07 -0500 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3FBstZwYKCj8ujuvtshpphmf.dpnrfnv-efwfmopohov.psh@flex--titusr.bounces.google.com>) id 1t98at-0003Kg-RC for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:06 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e29205f6063so2268550276.1 for ; Thu, 07 Nov 2024 11:55:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731009301; x=1731614101; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=sxbPXV2KES210ccGj2mQ/00ciXsa28hw8J0Q0KYSQDc=; b=T3NR1zQWeSRQFYRTQ1lEpwHC9/9dEwXDc1eZ2z1VeB0tCL+w0qLQgPFV6wSYmQXsZU bmhjT8IhxROI6YcLhGFcFtH1qGiStaD0OWANYIu7zoLI+4w08oAi2kdhI8UEexfAvkl/ nPeNDoRycOyiu3G+Gm400WyoiG1hW8OXxOiIu2HycUmCae3YmbYSdllsyFz7FXzjvLGF 1SYXLmRIaIR4xiyF0xQ4O7xUGY2UPCndkyH3pkGHmV50rgQonAMaP2jJnq60l+CdNcm+ rIq1N50WHCe2MhMD/WLxK/0T8ciBHBe8dErm8WKgC8TmTr+wVTTHErIAvApRXxLDILXk jvUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731009301; x=1731614101; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=sxbPXV2KES210ccGj2mQ/00ciXsa28hw8J0Q0KYSQDc=; b=BWtyApSHWh98lXLvyJez/LFZf46iJWr6u6SAlV8ZwhIE8PaYF2kqnlWelMiXR8UqS2 4tDGxsPk+C/oqypqL8xQYHxcypPCQQhGzFzmGUTVK5YhgboWUXhU2Zq9SVHQCpPEZ0EJ 6sSDxHS+Z9YYpJsmAKHatvpdSneRW3z5PE8b3GRRR7aU23JltlQAf8DREn3FzKkt7ZtB jW0BqO7ua/3bfChKFPk9KbQ0mq3cu1srK1EhQKWgen4PMrakdKPyGZuMSdRGdxoHU4SY /rGFLUHruFJIz+YSyQHGy9L1U64L2ommYAMD2k90C38D6dlAq81wl/PGW6qzsSFA+V2o 4A+g== X-Forwarded-Encrypted: i=1; AJvYcCXdf0mmoNl+CFiTrnbNzDBInvAO5pykv4wyJg81ivo/la8jvZHKoRaY9vnb/ae/3ZDxiCj3oI06mPla@nongnu.org X-Gm-Message-State: AOJu0YxIVddHZw/Q8uhmzOpFtBjdoPsMi8iF1j+TMzz01+ANIE1LH/tj p+xqKBuKJOQv+N71kjQ2/RIGX1NRyVm7mr3JYBbH+aRAhvCX5IHzQf+R0y73KISkMDKskZobYk6 ZPw== X-Google-Smtp-Source: AGHT+IE0q0PWUlih+47eGnqEzahF8cZwQc7/3aNVVz9lbHyqNxLtk29OTlyDgxo8JxJapjnvXSbpbZulJAY= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:dc:567e:c0a8:e14]) (user=titusr job=sendgmr) by 2002:a25:acd3:0:b0:e30:da65:7240 with SMTP id 3f1490d57ef6-e337f85bbf5mr577276.3.1731009300823; Thu, 07 Nov 2024 11:55:00 -0800 (PST) Date: Thu, 7 Nov 2024 19:54:50 +0000 In-Reply-To: <20241107195453.2684138-1-titusr@google.com> Mime-Version: 1.0 References: <20241107195453.2684138-1-titusr@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107195453.2684138-4-titusr@google.com> Subject: [PATCH 3/6] hw/gpio: add PCA9536 i2c gpio expander From: Titus Rwantare To: peter.maydell@linaro.org, minyard@acm.org, clg@redhat.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, philmd@linaro.org, venture@google.com, wuhaotsh@google.com, milesg@linux.vnet.ibm.com, Titus Rwantare Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3FBstZwYKCj8ujuvtshpphmf.dpnrfnv-efwfmopohov.psh@flex--titusr.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This device has the same register layout as the pca9538, but 4 fewer gpio pins. This commit lowers the number of pins initialised, and reuses the pca9538 logic. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Hao Wu Signed-off-by: Titus Rwantare --- hw/gpio/pca_i2c_gpio.c | 18 ++++++++++++++++++ include/hw/gpio/pca_i2c_gpio.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/hw/gpio/pca_i2c_gpio.c b/hw/gpio/pca_i2c_gpio.c index 2486c620e3..b911187e34 100644 --- a/hw/gpio/pca_i2c_gpio.c +++ b/hw/gpio/pca_i2c_gpio.c @@ -336,6 +336,19 @@ static void pca9538_gpio_class_init(ObjectClass *klass, void *data) k->send = pca953x_send; } +static void pca9536_gpio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); + PCAGPIOClass *pc = PCA_I2C_GPIO_CLASS(klass); + + dc->desc = "PCA9536 4-bit I/O expander"; + pc->num_pins = PCA9536_NUM_PINS; + + k->recv = pca953x_recv; + k->send = pca953x_send; +} + static void pca_i2c_gpio_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -386,6 +399,11 @@ static const TypeInfo pca_gpio_types[] = { .parent = TYPE_PCA_I2C_GPIO, .class_init = pca9538_gpio_class_init, }, + { + .name = TYPE_PCA9536_GPIO, + .parent = TYPE_PCA_I2C_GPIO, + .class_init = pca9536_gpio_class_init, + }, }; DEFINE_TYPES(pca_gpio_types); diff --git a/include/hw/gpio/pca_i2c_gpio.h b/include/hw/gpio/pca_i2c_gpio.h index 61e5853c24..f325563dc7 100644 --- a/include/hw/gpio/pca_i2c_gpio.h +++ b/include/hw/gpio/pca_i2c_gpio.h @@ -21,6 +21,7 @@ #define PCA_I2C_MAX_PINS 16 #define PCA6416_NUM_PINS 16 #define PCA9538_NUM_PINS 8 +#define PCA9536_NUM_PINS 4 typedef struct PCAGPIOClass { I2CSlaveClass parent; @@ -64,5 +65,6 @@ OBJECT_DECLARE_TYPE(PCAGPIOState, PCAGPIOClass, PCA_I2C_GPIO) #define TYPE_PCA6416_GPIO "pca6416" #define TYPE_PCA9538_GPIO "pca9538" +#define TYPE_PCA9536_GPIO "pca9536" #endif From patchwork Thu Nov 7 19:54:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13867051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B44CFD5D687 for ; Thu, 7 Nov 2024 19:56:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t98b2-0001ao-0x; Thu, 07 Nov 2024 14:55:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3FhstZwYKCkEwlwxvujrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--titusr.bounces.google.com>) id 1t98ax-0001VI-8j for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:07 -0500 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3FhstZwYKCkEwlwxvujrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--titusr.bounces.google.com>) id 1t98at-0003L7-RH for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:06 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e02fff66a83so2308645276.0 for ; Thu, 07 Nov 2024 11:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731009302; x=1731614102; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=Dhx3Bv91IwsNiKrqW6EopdF6ygF7pLBG+NH0I9FnnMU=; b=HJOq6v5rhqbMrcftI+/LxDpc/WkswW27a69yG2M7nZz6OT0iG2Fcghlv3gPFVjQr3z 1HNV4wvzOms03U5fvZ/i6GQlAL/Pn7sUjpEGvhtXfQxErjHXZD7s4/IxUE3VdJNG+8+J gttdY/1hSxQlIr4objVtIODodZSwZn6NPCgUoncVn6KcfZiKtNazC1MC/47wjDUWwhW1 eJCoUwVuPv4ehiBASv2PC3i4AK1hhMCYlKbsc0Q/ixvjFhn2t3j4EWfh8r2Oah9mZIDK 6dFsO0p7LyBqYwmV+ESDnNGEMdRZAeoiR5JSB94Eta9OaNjqLjz4tOMHr0HS2tjlAZ/z fcAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731009302; x=1731614102; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Dhx3Bv91IwsNiKrqW6EopdF6ygF7pLBG+NH0I9FnnMU=; b=uxaC8iDK7cy7y5PUpdOQChqBVxAXJjor2EGRrvCpOh5PKP5oMjcsjzO/fd9zIGp48Q GEugi6So/q4sjcbtfaRNSxxpyGHWjCET06lsy+m8Tlu0HuhjLHTGMSZZ1fSdduDRopQf fdFTIG9jefhjSvIHcdMrLFLtovQ8tuDpvw3WH/EPadSbdvUCVyM7qawxW12TscwYevxo XIGaxSsz5KvB3nwbLOK5JIejlxB8SgEJud3Hz8cikMIONGUwUD+KbxGkWhIj5qlbJt/c fYbYmnMicDAxsjqAfgwrSa0Ha/ZPJI8qbhM3qQOlf0GAQxgX+34efAE+9pdVOECDQwmJ LjfA== X-Forwarded-Encrypted: i=1; AJvYcCVmf+exFdEpBwqFP72sHnizfMGPlMWxmgqjLksdpLOHLOMymJ1El/fNDISMe7prmyAGDtcoxvw/djax@nongnu.org X-Gm-Message-State: AOJu0YwVbuV4ydTXrs/tiC3Kx4cbewTGpcicWuYrH/7A+8z2yY49bLku iRfgePd24h2kT7cw2IllybQ2ihgwrEE21TD7clN9cQqvy2pg+cIWydp5JPbnjmJdarxS8qSEbIK gTg== X-Google-Smtp-Source: AGHT+IEmlFuTkhdwv2WvBWxO94zsQ4xYCaZCgfhNKEGamC4qH1sUe3agkHFV+x8p66IVVRphgRWtEAm1cNo= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:dc:567e:c0a8:e14]) (user=titusr job=sendgmr) by 2002:a25:aac4:0:b0:e2b:da82:f695 with SMTP id 3f1490d57ef6-e337f8c1754mr158276.6.1731009302052; Thu, 07 Nov 2024 11:55:02 -0800 (PST) Date: Thu, 7 Nov 2024 19:54:51 +0000 In-Reply-To: <20241107195453.2684138-1-titusr@google.com> Mime-Version: 1.0 References: <20241107195453.2684138-1-titusr@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107195453.2684138-5-titusr@google.com> Subject: [PATCH 4/6] hw/i2c: add canonical path to i2c event traces From: Titus Rwantare To: peter.maydell@linaro.org, minyard@acm.org, clg@redhat.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, philmd@linaro.org, venture@google.com, wuhaotsh@google.com, milesg@linux.vnet.ibm.com, Titus Rwantare Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3FhstZwYKCkEwlwxvujrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--titusr.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Titus Rwantare Acked-by: Corey Minyard --- hw/i2c/core.c | 8 +++++--- hw/i2c/trace-events | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 4cf30b2c86..d238311776 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -161,7 +161,8 @@ static int i2c_do_start_transfer(I2CBus *bus, uint8_t address, start condition. */ if (sc->event) { - trace_i2c_event(event == I2C_START_SEND ? "start" : "start_async", + trace_i2c_event(DEVICE(s)->canonical_path, + event == I2C_START_SEND ? "start" : "start_async", s->address); rv = sc->event(s, event); if (rv && !bus->broadcast) { @@ -244,7 +245,7 @@ void i2c_end_transfer(I2CBus *bus) I2CSlave *s = node->elt; sc = I2C_SLAVE_GET_CLASS(s); if (sc->event) { - trace_i2c_event("finish", s->address); + trace_i2c_event(DEVICE(s)->canonical_path, "finish", s->address); sc->event(s, I2C_FINISH); } QLIST_REMOVE(node, next); @@ -321,7 +322,8 @@ void i2c_nack(I2CBus *bus) QLIST_FOREACH(node, &bus->current_devs, next) { sc = I2C_SLAVE_GET_CLASS(node->elt); if (sc->event) { - trace_i2c_event("nack", node->elt->address); + trace_i2c_event(DEVICE(node->elt)->canonical_path, + "nack", node->elt->address); sc->event(node->elt, I2C_NACK); } } diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events index f708a7ace1..e5f2dc643e 100644 --- a/hw/i2c/trace-events +++ b/hw/i2c/trace-events @@ -9,7 +9,7 @@ bitbang_i2c_data(unsigned clk, unsigned dat, unsigned old_out, unsigned new_out) # core.c -i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)" +i2c_event(const char *id, const char *event, uint8_t address) "%s: %s(addr:0x%02x)" i2c_send(uint8_t address, uint8_t data) "send(addr:0x%02x) data:0x%02x" i2c_send_async(uint8_t address, uint8_t data) "send_async(addr:0x%02x) data:0x%02x" i2c_recv(uint8_t address, uint8_t data) "recv(addr:0x%02x) data:0x%02x" From patchwork Thu Nov 7 19:54:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13867055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78541D5D688 for ; Thu, 7 Nov 2024 19:56:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t98b3-0001cH-GE; Thu, 07 Nov 2024 14:55:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3FxstZwYKCkIxmxywvksskpi.gsquiqy-hiziprsrkry.svk@flex--titusr.bounces.google.com>) id 1t98ax-0001VF-2a for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:07 -0500 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3FxstZwYKCkIxmxywvksskpi.gsquiqy-hiziprsrkry.svk@flex--titusr.bounces.google.com>) id 1t98au-0003Ld-KH for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:06 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6ea7cfb6e0fso27083097b3.0 for ; Thu, 07 Nov 2024 11:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731009303; x=1731614103; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7hncGgySUr3tVJodOoCwhdjUjxWooLQLxe671zubbZI=; b=ubMBkcOCjnrX0yitE9Y2cAHiuTPQo9TFSy6y3II2qBSL0svu73jRx6Lu8XsMpBNc3N L7iFepWWwQ/ehdD0gCtk8fU5/QR76DrzUx/RiInSOWhL6ScgLrF5BrXIxEv5GpkaC9km gU/P/PHkh9pjTwqY68DJXdgANQNcFH5QIZ9X4t+CTTtiC3LyUkxGAwFtZdzj32pGkpm5 OD+UipxJ12TRtd6sczEf8oEnwd46lVnHRDgItqqkvs63IK964kA3qUWrjXdatDH61JOL YS+2FPI53uLE1oAspMtdFQvEdheIBJzlrsB3mNjuhmEJP08VNTDlo11noAaXd1V13n29 Q/HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731009303; x=1731614103; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7hncGgySUr3tVJodOoCwhdjUjxWooLQLxe671zubbZI=; b=s7u4lK6vk2SqN4CL8076XnTdwurBq866cp+RYaFGMv/otQPOpYDYx997wiMZigI6GN 9y/rmevDFvc8/5mN4M46VbU1qHUT4NY9SeaLtS8rgrEtlHKt2BCRHMkos45TjVm/OZpE 2IM5Ez9T/+E45yJ5RZcHIvpIpG1+3aUQGUPAFVaE3TK69FlSq9SQbHH7h4+KlYnbaotD vEhVjehCSUgPb/XL+QmuMoYN/1X59QjoB7Aq9kTXmAkkNOwHnAYExjgNfgVeYzwKLlSa U8qEOHqJc1+MU2MiqZINLqB+xrAbWc9sIS3LUGEkBrPHDlsJ4o4U7+lS6RYXRd2MOnJ7 KtGQ== X-Forwarded-Encrypted: i=1; AJvYcCWWZXGC4O1IlMwg1pkZbZWmWbeD3JWDcBfBSNIq2Xmlh87QZp4LMwB4XiJvSJNE9sW2B5gYQGxKPyIQ@nongnu.org X-Gm-Message-State: AOJu0Yx/PPwgb6m1xoJBnJeJ1JFd7ebsps0lBhL3WIgtqWqW+0p7k7S0 +0pMpjUUYx02gvjgX8x2jDY6WJuKhYbw78sTrx9f+uN5IBchfuqMyLFNnTm9wCLIY1cfwyQ4bQk mtQ== X-Google-Smtp-Source: AGHT+IG/BBbjNIb+sHx+VtZ8fCT9DJ18NOQeJo8RTwkKJK1ExhcusVN0vYb9C/DWHhCHULHbKC5LPEovtFM= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:dc:567e:c0a8:e14]) (user=titusr job=sendgmr) by 2002:a5b:acd:0:b0:e30:d561:dad4 with SMTP id 3f1490d57ef6-e337f8417bemr3381276.2.1731009303114; Thu, 07 Nov 2024 11:55:03 -0800 (PST) Date: Thu, 7 Nov 2024 19:54:52 +0000 In-Reply-To: <20241107195453.2684138-1-titusr@google.com> Mime-Version: 1.0 References: <20241107195453.2684138-1-titusr@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107195453.2684138-6-titusr@google.com> Subject: [PATCH 5/6] hw/arm: imply I2C_DEVICES on NPCM7xx From: Titus Rwantare To: peter.maydell@linaro.org, minyard@acm.org, clg@redhat.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, philmd@linaro.org, venture@google.com, wuhaotsh@google.com, milesg@linux.vnet.ibm.com, Titus Rwantare Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3FxstZwYKCkIxmxywvksskpi.gsquiqy-hiziprsrkry.svk@flex--titusr.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Titus Rwantare --- hw/arm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 1b25e73578..30480dad7b 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -465,6 +465,7 @@ config NPCM7XX bool default y depends on TCG && ARM + imply I2C_DEVICES select A9MPCORE select ADM1266 select ADM1272 From patchwork Thu Nov 7 19:54:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13867056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0A0DAD5D687 for ; Thu, 7 Nov 2024 19:57:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t98b4-0001cM-Cw; Thu, 07 Nov 2024 14:55:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3GBstZwYKCkMynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1t98ay-0001Xg-DF for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:08 -0500 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3GBstZwYKCkMynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1t98aw-0003Lt-40 for qemu-devel@nongnu.org; Thu, 07 Nov 2024 14:55:08 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6ea90b6ee2fso24432357b3.1 for ; Thu, 07 Nov 2024 11:55:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731009304; x=1731614104; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2TPajN/xK866wB9/V0io4yin6lsJZUCZq19AIoNDrlE=; b=34cAvccrIHy7K54KuYIfa8mCgzS11KozYsQDWsovLVkAeUzmn4uYwAcc3EfgcyLFaT Nm1AdPdTtWNyWfe92h1G8TiCdTvPJS3xB/81snLoefNo8pHVzQH3jQCavPRtSAq4xz7/ CKmMLQzwED/FwS8We3zxfBuWXmg8CW8GKAho5UUz7+U+aL6fsNVwZd9/nVt9orexePci 5xnNOTuL0+62Vv6BEkP3DUhTtb1J+plSYEiuPstsLzSEnEEbLz8tgLFIorrwTsg9NFPJ x0BhkCRVCl+qo+F5n1KLu6WZF1uEbHD64gfeKnOEDKeHH29zBh1lpf8TrwleGnGzdM0t LHvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731009304; x=1731614104; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2TPajN/xK866wB9/V0io4yin6lsJZUCZq19AIoNDrlE=; b=xDuNlR2s+swb6/IYAxMGgYUUIN+wnFsxHrm1yy4D0LME3imfSWtrnHsDsMPoH0pY3n /r72H9x1ETQsnOZ/70Ahf4gWDE3uUqG79fuId2CHjLschWGQj2ELZXxVIdrfi1CL/NH2 DYWumL/55lYv41PMkylaUQMN5QXWupeaaPPW/TTTSkH/Skn/QI3uwqvgOc+AU+FP5Gh1 A5+08ySScFZIrJgFYDpvlr+sW7KmSQ5oXk4SA/UGqEeN85ZWk0J7Fkq1fZwj2SJj7Jj1 8vanN1NYn71I3eLIvQpPqOIn/XnWvSG7l7OLoxuCXm2rf8FChhuYDQXhJ9T6OeMtTLR6 NmMQ== X-Forwarded-Encrypted: i=1; AJvYcCV+h4g+Z8bt5JYeMhxMqfk9wMwxdwCXxMGQF6dmTW1k9A1K+cydqnuaJdFpVWugFWZw7aBAIXk/phw4@nongnu.org X-Gm-Message-State: AOJu0YyFodMbnDWBmTBsLHzG4NMX/S9iTpMGVPwWvVbMst6Kb1/rtKuA krGUeploSuBuLDceuWFk8p011sEgx7d2f7Zg+HUCAcLeLPxxG8O/mQpJqMxOQNIwLVNeERlx1TK Aig== X-Google-Smtp-Source: AGHT+IEzEwAfAp07uy20252K/bFORWiekex+xIIr144a5YKUpOP1oPmKiItVm5RBIBNDcMtB/WWZ/cyXDJs= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:dc:567e:c0a8:e14]) (user=titusr job=sendgmr) by 2002:a05:690c:6908:b0:6ea:71c3:6cc3 with SMTP id 00721157ae682-6eaddfe2f18mr907b3.8.1731009304063; Thu, 07 Nov 2024 11:55:04 -0800 (PST) Date: Thu, 7 Nov 2024 19:54:53 +0000 In-Reply-To: <20241107195453.2684138-1-titusr@google.com> Mime-Version: 1.0 References: <20241107195453.2684138-1-titusr@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107195453.2684138-7-titusr@google.com> Subject: [PATCH 6/6] hw/arm: add Quanta GSZ bmc machine From: Titus Rwantare To: peter.maydell@linaro.org, minyard@acm.org, clg@redhat.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, philmd@linaro.org, venture@google.com, wuhaotsh@google.com, milesg@linux.vnet.ibm.com, Titus Rwantare Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3GBstZwYKCkMynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This patch adds the quanta-gsz-bmc target, a current Google machine of the day. This machine will be used as a platform to enable features such as the PECI bmc interface, and Intel eSPI virtual wire interface in QEMU. Signed-off-by: Titus Rwantare --- hw/arm/npcm7xx_boards.c | 160 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c index e229efb447..85c3f8e9a0 100644 --- a/hw/arm/npcm7xx_boards.c +++ b/hw/arm/npcm7xx_boards.c @@ -48,6 +48,8 @@ #define NPCM750_EVB_POWER_ON_STRAPS ( \ NPCM7XX_POWER_ON_STRAPS_DEFAULT & ~NPCM7XX_PWRON_STRAP_J2EN) #define QUANTA_GSJ_POWER_ON_STRAPS NPCM7XX_POWER_ON_STRAPS_DEFAULT +#define QUANTA_GSZ_POWER_ON_STRAPS ( \ + NPCM7XX_POWER_ON_STRAPS_DEFAULT & ~NPCM7XX_PWRON_STRAP_SFAB) #define QUANTA_GBS_POWER_ON_STRAPS ( \ NPCM7XX_POWER_ON_STRAPS_DEFAULT & ~NPCM7XX_PWRON_STRAP_SFAB) #define KUDO_BMC_POWER_ON_STRAPS NPCM7XX_POWER_ON_STRAPS_DEFAULT @@ -269,6 +271,129 @@ static void quanta_gsj_fan_init(NPCM7xxMachine *machine, NPCM7xxState *soc) npcm7xx_connect_pwm_fan(soc, &splitter[2], 0x05, 1); } +static void quanta_gsz_i2c_init(NPCM7xxState *soc) +{ + DeviceState *dev; + I2CSlave *i2c_mux; + + /* i2c1 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), TYPE_PCA9548, + 0x75); + /* pca6416@0x20 */ + dev = DEVICE(i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 3), + "pca6416", 0x20)); + object_property_set_uint(OBJECT(dev), "gpio_config", 0xF00, &error_abort); + object_property_set_uint(OBJECT(dev), "gpio_input", 0xF00, &error_abort); + + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), + TYPE_PCA9548, 0x77); + + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 0), "raa229004", 0x72); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 1), "raa229004", 0x72); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "isl69260", 0x72); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 3), "isl69260", 0x72); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 4), "isl69260", 0x72); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 5), "isl69260", 0x72); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 6), "adm1272", 0x1f); + + /* i2c2 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), + TYPE_PCA9548, 0x77); + /* - channel 0: tps546d24 @25 + * - channel 1: delta,dps800 @69 + */ + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 1), "raa228000", 0x68); + /* - channel 2: delta,dps800 @68 */ + /* max31725 is compatible with tmp105. */ + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 4), "tmp105", 0x5c); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 5), "tmp105", 0x5c); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 6), "tmp105", 0x5c); + + /* i2c3 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), TYPE_PCA9548, + 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + + /* i2c4 */ + /* mobo_fru_1 */ + at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 4), 0x50, 8192); + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), + TYPE_PCA9548, 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 0), "max34451", 0x59); + /* mobo_fru_2 */ + at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 2), 0x55, 32768); + + dev = DEVICE(i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 3), + "pca6416", 0x20)); + object_property_set_uint(OBJECT(dev), "gpio_config", 0x4000, &error_abort); + object_property_set_uint(OBJECT(dev), "gpio_input", 0x4000, &error_abort); + + dev = DEVICE(i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 4), + "pca6416", 0x20)); + object_property_set_uint(OBJECT(dev), "gpio_config", 0xFFFF, &error_abort); + object_property_set_uint(OBJECT(dev), "gpio_input", 0x0000, &error_abort); + + /* pdb_fru */ + at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 6), 0x55, 8192); + + /* i2c5 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 5), TYPE_PCA9548, + 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + + /* i2c6 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), TYPE_PCA9548, + 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + + /* i2c7 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 7), TYPE_PCA9548, + 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + + /* i2c8 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 8), TYPE_PCA9548, + 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + + /* i2c9 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 9), TYPE_PCA9548, + 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + + /* i2c10 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 10), + TYPE_PCA9548, 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 1), "pca9538", 0x72); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + /* i2c11 */ + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 11), + TYPE_PCA9548, 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "pca9538", 0x72); + + /* i2c12 */ + + /* i2c13 */ + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 13), "pca6416", 0x22); + + /* i2c14 */ + /* LEDs and PE Resets */ + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 14), "pca6416", 0x20); + + /* bmc_fru_1 */ + at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 14), 0x55, 8192); + + i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 14), + TYPE_PCA9548, 0x77); + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 0), "max34451", 0x59); + + /* max31725 is compatible with tmp105 */ + i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 4), "tmp105", 0x5c); + + /* i2c15 */ + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 15), TYPE_PCA9546, 0x75); +} + static void quanta_gbs_i2c_init(NPCM7xxState *soc) { /* @@ -392,6 +517,25 @@ static void quanta_gsj_init(MachineState *machine) npcm7xx_load_kernel(machine, soc); } +static void quanta_gsz_init(MachineState *machine) +{ + NPCM7xxState *soc; + + soc = npcm7xx_create_soc(machine, QUANTA_GSZ_POWER_ON_STRAPS); + npcm7xx_connect_dram(soc, machine->ram); + qdev_realize(DEVICE(soc), NULL, &error_fatal); + + npcm7xx_load_bootrom(machine, soc); + npcm7xx_connect_flash(&soc->fiu[0], 0, "mx66u51235f", + drive_get(IF_MTD, 0, 0)); + npcm7xx_connect_flash(&soc->fiu[1], 0, "mx66u51235f", + drive_get(IF_MTD, 3, 0)); + + quanta_gsz_i2c_init(soc); + sdhci_attach_drive(&soc->mmc.sdhci, 0); + npcm7xx_load_kernel(machine, soc); +} + static void quanta_gbs_init(MachineState *machine) { NPCM7xxState *soc; @@ -496,6 +640,18 @@ static void gsj_machine_class_init(ObjectClass *oc, void *data) mc->default_ram_size = 512 * MiB; }; +static void gsz_machine_class_init(ObjectClass *oc, void *data) +{ + NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_CLASS(oc); + MachineClass *mc = MACHINE_CLASS(oc); + + npcm7xx_set_soc_type(nmc, TYPE_NPCM730); + + mc->desc = "Quanta GSZ (Cortex-A9)"; + mc->init = quanta_gsz_init; + mc->default_ram_size = 1 * GiB; +} + static void gbs_bmc_machine_class_init(ObjectClass *oc, void *data) { NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_CLASS(oc); @@ -548,6 +704,10 @@ static const TypeInfo npcm7xx_machine_types[] = { .name = MACHINE_TYPE_NAME("quanta-gsj"), .parent = TYPE_NPCM7XX_MACHINE, .class_init = gsj_machine_class_init, + }, { + .name = MACHINE_TYPE_NAME("quanta-gsz-bmc"), + .parent = TYPE_NPCM7XX_MACHINE, + .class_init = gsz_machine_class_init, }, { .name = MACHINE_TYPE_NAME("quanta-gbs-bmc"), .parent = TYPE_NPCM7XX_MACHINE,