From nobody Thu May 9 01:41:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1679423320; cv=none; d=zohomail.com; s=zohoarc; b=EFCQu+/GlIjZZRsO221tfFlObRDEsjYJSAd2Co20TMovXbc9A+hBOxSpY6QYSprV7UgVDmQwAG2D9N9v6QWNFC352BhEhU3rfetKt4b89GQko6J5swZsa0jQGkZ2pKe3hhBlhFAakHLyanC8bnlD2EsLGn5rY9g0B25WogQjhLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679423320; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3CoTfX7VBOzqqGvrBwbqNgL1pulI1GCVXMwtzgIXMpg=; b=N2Bia0o6sjul6+EfyWO+sm1H+hXpeVk4SNdAD1USA56ZuZVV0az0pSQPA+Xsa6hN0x8Jhn9pHoe82E6mygPDp++da3LoTDVfiG5blc5r8BW18E/RsJRV21dp8YcQaNZ8DBVuzb9TlsFGtZMB1Uf9BDyQY4Fr2b3AC1GAsJZrjZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1679423320720545.6109825069921; Tue, 21 Mar 2023 11:28:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pegiL-0002uR-JC; Tue, 21 Mar 2023 14:28:05 -0400 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 <3L_cZZAcKCqwhQZfgdQSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--venture.bounces.google.com>) id 1pegiJ-0002t7-OW for qemu-devel@nongnu.org; Tue, 21 Mar 2023 14:28:03 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3L_cZZAcKCqwhQZfgdQSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--venture.bounces.google.com>) id 1pegiH-0006Nl-L4 for qemu-devel@nongnu.org; Tue, 21 Mar 2023 14:28:03 -0400 Received: by mail-yb1-xb49.google.com with SMTP id x15-20020a25accf000000b00b3b4535c48dso17047806ybd.7 for ; Tue, 21 Mar 2023 11:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679423280; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=3CoTfX7VBOzqqGvrBwbqNgL1pulI1GCVXMwtzgIXMpg=; b=UP9d4mTViuZ4Jlhv+SXQo9iUzwVuMYxpY14WgrfUPQFCfXA9Rjouy0xoU5LNKSahZV +MfgKo0ZFrpfQLVx0Jo97hU/cMjEGHBNlF8C8kfHcLYahNHA4eLQfH/GWD1AulSEFOgg TCsJ2/MzBJ+/i90JUcUiZHYy+B+GEp0RXkzEK+ot0qIcR9ZizITYw9sGlVfvsT3WI6wM yNfovYpA8GooI7F9JSRBTHH8o1e3jI0HOdmmKHFz6+RJeKEP77PwUk64dPCWDu8e6ZK2 H/PuZSk41V1XQjwdh6O+INIgNOiZFDLbFKUCuNOCRlNkI62YO7uUOr4jRT8t6vRy+gXf f9JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679423280; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3CoTfX7VBOzqqGvrBwbqNgL1pulI1GCVXMwtzgIXMpg=; b=YoTx1Bmz/cGbG/x26vgGA0mh9FwvoMTC51tfI4XvgB/+XfCcgie78/SeOfhD5fzHbs Lh9GyZNHa/r2m2pweO6I+hOhSk5L4JshRGRKwEI93bTGktplJFglDux4ifmpZ6ssVIr4 zPRZ839gi3kuD0EBRUuckQywv6Bwy1TFN1t6XxcAsmzrdeH3R1fhHci8S9OHBYbhkONP EgFofbnLKVFmeUgoGFIQhlR9vw/AQWrspM9ECgVDIK0XItnuapYdFl8OP1QnhOF4N+oa iu5Uj0eTm+rWNFywEfrnmaT6rW7Xz1xoz6Z9x6dwIP7audJuu1M8GdMWLoR+wahklWGc pFGA== X-Gm-Message-State: AAQBX9de5VIBbCpsDxIZ/w6uKIZYml/4Zr2uJpqwu8/gbMTqYxCltOim XBebKL520JYMX0vYQRSUNRFVgTwF/6Rb X-Google-Smtp-Source: AKy350YxHDlw9YGFVub8DF4zaa2db5YGTvHwTUtbZvDq0MG79VskLFeAl83/btjrZu16jLjZufqWjsjrOZTd X-Received: from venture.svl.corp.google.com ([2620:15c:2a3:201:9e3c:55e4:5616:81]) (user=venture job=sendgmr) by 2002:a81:a7c1:0:b0:545:5b2c:4bfb with SMTP id e184-20020a81a7c1000000b005455b2c4bfbmr917889ywh.8.1679423279953; Tue, 21 Mar 2023 11:27:59 -0700 (PDT) Date: Tue, 21 Mar 2023 11:27:44 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230321182744.2814034-1-venture@google.com> Subject: [PATCH RESEND] hw/i2c: Enable an id for the pca954x devices From: Patrick Venture To: cminyard@mvista.com, peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, Patrick Venture , Hao Wu , "=?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?=" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3L_cZZAcKCqwhQZfgdQSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--venture.bounces.google.com; helo=mail-yb1-xb49.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1679423322397100001 Content-Type: text/plain; charset="utf-8" This allows the devices to be more readily found and specified. Without setting the id field, they can only be found by device type name, which doesn't let you specify the second of the same device type behind a bus. Tested: Verified that by default the device was findable with the id 'pca954x[77]', for an instance attached at that address. Signed-off-by: Patrick Venture Reviewed-by: Hao Wu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/i2c/i2c_mux_pca954x.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/i2c/i2c_mux_pca954x.c b/hw/i2c/i2c_mux_pca954x.c index a9517b612a..4f8c2d6ae1 100644 --- a/hw/i2c/i2c_mux_pca954x.c +++ b/hw/i2c/i2c_mux_pca954x.c @@ -20,6 +20,7 @@ #include "hw/i2c/i2c_mux_pca954x.h" #include "hw/i2c/smbus_slave.h" #include "hw/qdev-core.h" +#include "hw/qdev-properties.h" #include "hw/sysbus.h" #include "qemu/log.h" #include "qemu/module.h" @@ -43,6 +44,8 @@ typedef struct Pca954xState { =20 bool enabled[PCA9548_CHANNEL_COUNT]; I2CBus *bus[PCA9548_CHANNEL_COUNT]; + + char *id; } Pca954xState; =20 /* @@ -181,6 +184,17 @@ static void pca9548_class_init(ObjectClass *klass, voi= d *data) s->nchans =3D PCA9548_CHANNEL_COUNT; } =20 +static void pca954x_realize(DeviceState *dev, Error **errp) +{ + Pca954xState *s =3D PCA954X(dev); + DeviceState *d =3D DEVICE(s); + if (s->id) { + d->id =3D g_strdup(s->id); + } else { + d->id =3D g_strdup_printf("pca954x[%x]", s->parent.i2c.address); + } +} + static void pca954x_init(Object *obj) { Pca954xState *s =3D PCA954X(obj); @@ -197,6 +211,11 @@ static void pca954x_init(Object *obj) } } =20 +static Property pca954x_props[] =3D { + DEFINE_PROP_STRING("id", Pca954xState, id), + DEFINE_PROP_END_OF_LIST() +}; + static void pca954x_class_init(ObjectClass *klass, void *data) { I2CSlaveClass *sc =3D I2C_SLAVE_CLASS(klass); @@ -209,9 +228,12 @@ static void pca954x_class_init(ObjectClass *klass, voi= d *data) rc->phases.enter =3D pca954x_enter_reset; =20 dc->desc =3D "Pca954x i2c-mux"; + dc->realize =3D pca954x_realize; =20 k->write_data =3D pca954x_write_data; k->receive_byte =3D pca954x_read_byte; + + device_class_set_props(dc, pca954x_props); } =20 static const TypeInfo pca954x_info[] =3D { --=20 2.35.1.894.gb6a874cedc-goog