From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109103; cv=none; d=zohomail.com; s=zohoarc; b=Kih2dX4m5sFdCn259uocjE8oU3QofRmFWDTjGbDpW+lsrKGqufCp9sDKRPcYAqxd2MdItZgjk21YWl//8J3e3nu5+KtaO9R4amJxGprD2dIBYCJzD3Bj8sk6dmpieU+fF3zchF6790gZENXLKpxV4tdCNdF3uMubbSTT88FGDrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109103; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BgjDTCoIx+y9Zc2qMSrwigZ2m9wFUK438n4TkTz6H+g=; b=PLf+yhJg1UMsXIoSjfEedBg2fw/GYo0p3WuDPVvVNJ/iK4zvpNLDxP2Cc2mNaRWPH5lgftdzOwJzfOUwM9k29pavyZX+nWrudYzks5DPYFTR+YlFqBG+XetEh8JT3WNzzTMuIXuw4LlEkpDi3JYCkUy97LaRGwLETj2kCYjL4W0= 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 1701109103020955.3551502729; Mon, 27 Nov 2023 10:18:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gAr-0001TG-Np; Mon, 27 Nov 2023 13:17:37 -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 ) id 1r7gAo-0001SZ-Se; Mon, 27 Nov 2023 13:17:35 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gAl-00016d-M2; Mon, 27 Nov 2023 13:17:34 -0500 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARIEK4H026923; Mon, 27 Nov 2023 18:17:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un074r2vx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:19 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARIEdhU027383; Mon, 27 Nov 2023 18:17:18 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un074r2vj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:18 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGvBin009176; Mon, 27 Nov 2023 18:17:18 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ukumyapgp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:18 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHHwl35521230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:17 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 49A7B58058; Mon, 27 Nov 2023 18:17:17 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1872D58057; Mon, 27 Nov 2023 18:17:17 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:17 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=BgjDTCoIx+y9Zc2qMSrwigZ2m9wFUK438n4TkTz6H+g=; b=ElIsmHP76HHPK+SD5DFVmsk/xxdHgBKPYA9WrMyzNLjYSHrnxIGv57zmChmd3fV9K6kv 0YCH7EZTGPL6Wyr5MWRmaNI8GWEqMa60parhusu+WIVQSfvCyifHqyG2YbK1U1W39RkS uAik4GguUyB8PQh9bIQ1jXGugwJiKAyXSNp/CdWhNqhmUTFXPoHomzOtDKTguc9dZCNG MI9jkeOFGbh2xuBVMco/hz5qi4AIKtSqOza4BGG6FcGQ2njIBKOLd8LrP+++D4Yy+KGT 9r+BfqMtRJKO9qjLMJ6fFIgz4tBT6qZcx3E1AWWAcGQCLJCuzNy46/6G50uApYDEw1qn bA== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab , Andrew Jeffery Subject: [PATCH v6 1/9] misc/pca9552: Fix inverted input status Date: Mon, 27 Nov 2023 12:16:47 -0600 Message-Id: <20231127181655.1997496-2-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 9NE6RMRVtIW4g3rKExJ-m66t_80acUxe X-Proofpoint-ORIG-GUID: 8kfKFeV5a6idaJeg1B_QLnW1eUOsv2z8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270125 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: none client-ip=148.163.158.5; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109106042000009 Content-Type: text/plain; charset="utf-8" The pca9552 INPUT0 and INPUT1 registers are supposed to hold the logical values of the LED pins. A logical 0 should be seen in the INPUT0/1 registers for a pin when its corresponding LSn bits are set to 0, which is also the state needed for turning on an LED in a typical usage scenario. Existing code was doing the opposite and setting INPUT0/1 bit to a 1 when the LSn bit was set to 0, so this commit fixes that. Reviewed-by: Andrew Jeffery Signed-off-by: Glenn Miles --- No change from previous version hw/misc/pca9552.c | 18 +++++++++++++----- tests/qtest/pca9552-test.c | 6 +++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index fff19e369a..445f56a9e8 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -36,7 +36,10 @@ typedef struct PCA955xClass PCA955xClass; =20 DECLARE_CLASS_CHECKERS(PCA955xClass, PCA955X, TYPE_PCA955X) - +/* + * Note: The LED_ON and LED_OFF configuration values for the PCA955X + * chips are the reverse of the PCA953X family of chips. + */ #define PCA9552_LED_ON 0x0 #define PCA9552_LED_OFF 0x1 #define PCA9552_LED_PWM0 0x2 @@ -112,13 +115,18 @@ static void pca955x_update_pin_input(PCA955xState *s) =20 switch (config) { case PCA9552_LED_ON: - qemu_set_irq(s->gpio[i], 1); - s->regs[input_reg] |=3D 1 << input_shift; - break; - case PCA9552_LED_OFF: + /* Pin is set to 0V to turn on LED */ qemu_set_irq(s->gpio[i], 0); s->regs[input_reg] &=3D ~(1 << input_shift); break; + case PCA9552_LED_OFF: + /* + * Pin is set to Hi-Z to turn off LED and + * pullup sets it to a logical 1. + */ + qemu_set_irq(s->gpio[i], 1); + s->regs[input_reg] |=3D 1 << input_shift; + break; case PCA9552_LED_PWM0: case PCA9552_LED_PWM1: /* TODO */ diff --git a/tests/qtest/pca9552-test.c b/tests/qtest/pca9552-test.c index d80ed93cd3..ccca2b3d91 100644 --- a/tests/qtest/pca9552-test.c +++ b/tests/qtest/pca9552-test.c @@ -60,7 +60,7 @@ static void send_and_receive(void *obj, void *data, QGues= tAllocator *alloc) g_assert_cmphex(value, =3D=3D, 0x55); =20 value =3D i2c_get8(i2cdev, PCA9552_INPUT0); - g_assert_cmphex(value, =3D=3D, 0x0); + g_assert_cmphex(value, =3D=3D, 0xFF); =20 pca9552_init(i2cdev); =20 @@ -68,13 +68,13 @@ static void send_and_receive(void *obj, void *data, QGu= estAllocator *alloc) g_assert_cmphex(value, =3D=3D, 0x54); =20 value =3D i2c_get8(i2cdev, PCA9552_INPUT0); - g_assert_cmphex(value, =3D=3D, 0x01); + g_assert_cmphex(value, =3D=3D, 0xFE); =20 value =3D i2c_get8(i2cdev, PCA9552_LS3); g_assert_cmphex(value, =3D=3D, 0x54); =20 value =3D i2c_get8(i2cdev, PCA9552_INPUT1); - g_assert_cmphex(value, =3D=3D, 0x10); + g_assert_cmphex(value, =3D=3D, 0xEF); } =20 static void pca9552_register_nodes(void) --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109102; cv=none; d=zohomail.com; s=zohoarc; b=MptlIwR5O6U6Ctn/lDUa10ngAND7JKI7XeiZU3dWlOL2gOWybEEf+YoXEDKUfWPYoZp1mWQkYtrvcxjaoM7e2+Q5HHfM+YXYNpTSHvYDZlmllMQhNgLBz13bbE0AMqcU7h/ZvNg0Wj8T1NrcS238UuhB0NCFI7qj7DS06PlrJV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109102; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NKRYJONPAudISIxtAkocTvv6CRyILtTAJ9DEqUHH4Vk=; b=HbZDZp56UaZi7/6DKqUw+XKJcrKtEUwfrRMoFa6f6/iUIBPQ2yUCuVEBBH1VvCTtBAg5UUbmNcnYKOvschseh0aM395etP+Lpf4RKN7pn6d1TLN26VzvQD0mCWGiNHUfhYogZMOV/9nvW8QHXCTYnXTqGZ+RgUNQq8E19cSTuME= 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 1701109102953884.9994644327755; Mon, 27 Nov 2023 10:18:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gBI-0001Zp-Gw; Mon, 27 Nov 2023 13:18:04 -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 ) id 1r7gBF-0001Yj-Kp; Mon, 27 Nov 2023 13:18:01 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gBD-000196-Up; Mon, 27 Nov 2023 13:18:01 -0500 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARIEGGx026620; Mon, 27 Nov 2023 18:17:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un074r37m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:53 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARIFEGd029421; Mon, 27 Nov 2023 18:17:51 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un074r2xq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:51 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGqWWO001733; Mon, 27 Nov 2023 18:17:23 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ukwy1j0gp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:23 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHLER23593646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:22 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9366258058; Mon, 27 Nov 2023 18:17:21 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6297958057; Mon, 27 Nov 2023 18:17:21 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:21 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=NKRYJONPAudISIxtAkocTvv6CRyILtTAJ9DEqUHH4Vk=; b=rCnYl6QMJpDhdRT7Y2rwZAdLx0x84HsN3blQuPVLr+x4m24/Jxf3tFFe98GKZyJl3fb6 iK4bx/UCAEyaqOiWdBibOgerrFvInoeZBao6FcgWWwbYgoQGHJDV4sgNAtU6x+cRODR5 uHdqfXCNaycCSoCzdhyrgqnveZIJfgDr3PYlVbeHhwNDEu/aQxtzgLL8owA+wyHCe5Pb phd78UZyliJ9UFHcoZ4k2/G5rQUGcAHI99A4vVyf6Hca3KrY4vxkPff1ibQlRVd4trOy 8iKp3dnetOvXRKCMhCfWqIUtJBskqMbofbYl/UESIM4SEqQ4Q4GA0xnMbI/L+ptIXKFl uQ== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab , Andrew Jeffery Subject: [PATCH v6 2/9] misc/pca9552: Let external devices set pca9552 inputs Date: Mon, 27 Nov 2023 12:16:48 -0600 Message-Id: <20231127181655.1997496-3-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: NSc2qzYL9prgVQ_bDIyC5RWbHAsFRfXV X-Proofpoint-ORIG-GUID: skJzE9_ymemtTxLl6C5AU8OaaMDAJYTV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 clxscore=1011 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.158.5; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109106054000010 Content-Type: text/plain; charset="utf-8" Allow external devices to drive pca9552 input pins by adding input GPIO's to the model. This allows a device to connect its output GPIO's to the pca9552 input GPIO's. In order for an external device to set the state of a pca9552 pin, the pin must first be configured for high impedance (LED is off). If the pca9552 pin is configured to drive the pin low (LED is on), then external input will be ignored. Here is a table describing the logical state of a pca9552 pin given the state being driven by the pca9552 and an external device: PCA9552 Configured State | Hi-Z | Low | ------+------+-----+ External Hi-Z | Hi | Low | Device ------+------+-----+ State Low | Low | Low | ------+------+-----+ Reviewed-by: Andrew Jeffery Signed-off-by: Glenn Miles --- No change from previous version hw/misc/pca9552.c | 50 +++++++++++++++++++++++++++++++++------ include/hw/misc/pca9552.h | 3 ++- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index 445f56a9e8..fe876471c8 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -44,6 +44,8 @@ DECLARE_CLASS_CHECKERS(PCA955xClass, PCA955X, #define PCA9552_LED_OFF 0x1 #define PCA9552_LED_PWM0 0x2 #define PCA9552_LED_PWM1 0x3 +#define PCA9552_PIN_LOW 0x0 +#define PCA9552_PIN_HIZ 0x1 =20 static const char *led_state[] =3D {"on", "off", "pwm0", "pwm1"}; =20 @@ -110,22 +112,27 @@ static void pca955x_update_pin_input(PCA955xState *s) =20 for (i =3D 0; i < k->pin_count; i++) { uint8_t input_reg =3D PCA9552_INPUT0 + (i / 8); - uint8_t input_shift =3D (i % 8); + uint8_t bit_mask =3D 1 << (i % 8); uint8_t config =3D pca955x_pin_get_config(s, i); + uint8_t old_value =3D s->regs[input_reg] & bit_mask; + uint8_t new_value; =20 switch (config) { case PCA9552_LED_ON: /* Pin is set to 0V to turn on LED */ - qemu_set_irq(s->gpio[i], 0); - s->regs[input_reg] &=3D ~(1 << input_shift); + s->regs[input_reg] &=3D ~bit_mask; break; case PCA9552_LED_OFF: /* * Pin is set to Hi-Z to turn off LED and - * pullup sets it to a logical 1. + * pullup sets it to a logical 1 unless + * external device drives it low. */ - qemu_set_irq(s->gpio[i], 1); - s->regs[input_reg] |=3D 1 << input_shift; + if (s->ext_state[i] =3D=3D PCA9552_PIN_LOW) { + s->regs[input_reg] &=3D ~bit_mask; + } else { + s->regs[input_reg] |=3D bit_mask; + } break; case PCA9552_LED_PWM0: case PCA9552_LED_PWM1: @@ -133,6 +140,12 @@ static void pca955x_update_pin_input(PCA955xState *s) default: break; } + + /* update irq state only if pin state changed */ + new_value =3D s->regs[input_reg] & bit_mask; + if (new_value !=3D old_value) { + qemu_set_irq(s->gpio_out[i], !!new_value); + } } } =20 @@ -340,6 +353,7 @@ static const VMStateDescription pca9552_vmstate =3D { VMSTATE_UINT8(len, PCA955xState), VMSTATE_UINT8(pointer, PCA955xState), VMSTATE_UINT8_ARRAY(regs, PCA955xState, PCA955X_NR_REGS), + VMSTATE_UINT8_ARRAY(ext_state, PCA955xState, PCA955X_PIN_COUNT_MAX= ), VMSTATE_I2C_SLAVE(i2c, PCA955xState), VMSTATE_END_OF_LIST() } @@ -358,6 +372,7 @@ static void pca9552_reset(DeviceState *dev) s->regs[PCA9552_LS2] =3D 0x55; s->regs[PCA9552_LS3] =3D 0x55; =20 + memset(s->ext_state, PCA9552_PIN_HIZ, PCA955X_PIN_COUNT_MAX); pca955x_update_pin_input(s); =20 s->pointer =3D 0xFF; @@ -380,6 +395,26 @@ static void pca955x_initfn(Object *obj) } } =20 +static void pca955x_set_ext_state(PCA955xState *s, int pin, int level) +{ + if (s->ext_state[pin] !=3D level) { + uint16_t pins_status =3D pca955x_pins_get_status(s); + s->ext_state[pin] =3D level; + pca955x_update_pin_input(s); + pca955x_display_pins_status(s, pins_status); + } +} + +static void pca955x_gpio_in_handler(void *opaque, int pin, int level) +{ + + PCA955xState *s =3D PCA955X(opaque); + PCA955xClass *k =3D PCA955X_GET_CLASS(s); + + assert((pin >=3D 0) && (pin < k->pin_count)); + pca955x_set_ext_state(s, pin, level); +} + static void pca955x_realize(DeviceState *dev, Error **errp) { PCA955xClass *k =3D PCA955X_GET_CLASS(dev); @@ -389,7 +424,8 @@ static void pca955x_realize(DeviceState *dev, Error **e= rrp) s->description =3D g_strdup("pca-unspecified"); } =20 - qdev_init_gpio_out(dev, s->gpio, k->pin_count); + qdev_init_gpio_out(dev, s->gpio_out, k->pin_count); + qdev_init_gpio_in(dev, pca955x_gpio_in_handler, k->pin_count); } =20 static Property pca955x_properties[] =3D { diff --git a/include/hw/misc/pca9552.h b/include/hw/misc/pca9552.h index b6f4e264fe..c36525f0c3 100644 --- a/include/hw/misc/pca9552.h +++ b/include/hw/misc/pca9552.h @@ -30,7 +30,8 @@ struct PCA955xState { uint8_t pointer; =20 uint8_t regs[PCA955X_NR_REGS]; - qemu_irq gpio[PCA955X_PIN_COUNT_MAX]; + qemu_irq gpio_out[PCA955X_PIN_COUNT_MAX]; + uint8_t ext_state[PCA955X_PIN_COUNT_MAX]; char *description; /* For debugging purpose only */ }; =20 --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109170; cv=none; d=zohomail.com; s=zohoarc; b=Vu/XCIiEHMdTjXgp1bMvQ4/FmRw/F/ASKNyy3AUs0DxSO+IFOOGHbS+q7Nbxd/7oGOdsuVJAxkNcvvS62c5ub0pimvo7kjvQswkFpClO4qUETr43uu5I+36ku+KPyN5EExbS87FIORrRrpGOCN81HGxh5ev3lleghVwE+dxGp5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109170; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Dfqb2qJhtg/GBi590y/b4hRyYlUfuoAoT9C5EJ7PSlU=; b=VI1SuyNviop4mRQFzn886FRBWktG4udVzexzA2BitV9yTa+FJV9XTETkCQnGofViD4ZCXCas+yREbClT9O+EZsyJn6CLiGPCjcyjHmXL4BjyJ2Al2CgWUsM+mnQcABE5lFoEXSWTd/5s9CQynwQjY+7SgHJ5NI4NdseZX6+fwII= 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 1701109170234561.2076529276568; Mon, 27 Nov 2023 10:19:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gB2-0001W9-Qk; Mon, 27 Nov 2023 13:17:48 -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 ) id 1r7gB1-0001Uj-9I; Mon, 27 Nov 2023 13:17:47 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gAz-000185-6w; Mon, 27 Nov 2023 13:17:47 -0500 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARHljxA003329; Mon, 27 Nov 2023 18:17:36 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umytg0xj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:26 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARHlXLL002456; Mon, 27 Nov 2023 18:17:25 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umytg0xhm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:25 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGrZY4025568; Mon, 27 Nov 2023 18:17:24 GMT Received: from smtprelay01.wdc07v.mail.ibm.com ([172.16.1.68]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ukvrkacen-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:24 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay01.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHNZF26149606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:23 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77E8E5805D; Mon, 27 Nov 2023 18:17:23 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B10A58059; Mon, 27 Nov 2023 18:17:23 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:23 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=Dfqb2qJhtg/GBi590y/b4hRyYlUfuoAoT9C5EJ7PSlU=; b=INoWDALevJbGbg1PXvJupdqexDEGSvazv4Ei6DyCxf2yb7up/52Rdf6yqnpWUXrCffx+ 58A0B74lNPPKpTIspt9GXOvqEykhUDKdJ02bhuihUgltSYTZYilLlPA3RNK17y0Y5Oay dURC2RPhIVAhAtGIL5dRB6ApZJR4wIuwroAuZVWsi0otcuco+mABENd/ABn6Lxi1Nk26 gHWIRkS/Iq9ZmrhkO+n2/k9AKxNhUQQxKn6RxYp8d7LWNi606CYyN/MWuhHN6k0patXU RhivB7IPFRcpnEA377kVxTuxnJHPcBa6c+MGePNX0KF6PTSbfCLHoaTKEcW9/Y2adhhQ 5Q== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab Subject: [PATCH v6 3/9] ppc/pnv: New powernv10-rainier machine type Date: Mon, 27 Nov 2023 12:16:49 -0600 Message-Id: <20231127181655.1997496-4-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 54zSQaKisbebS0fhAN8oHiCfovi3yCxd X-Proofpoint-ORIG-GUID: bggRXXhh3kb7NskcKbKEjjCMaNFSoVrm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=825 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.156.1; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109171471000001 Create a new powernv machine type, powernv10-rainier, that will contain rainier-specific devices. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Glenn Miles --- No change from previous version hw/ppc/pnv.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 0297871bdd..08704ce695 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -2251,7 +2251,7 @@ static void pnv_machine_power9_class_init(ObjectClass= *oc, void *data) machine_class_allow_dynamic_sysbus_dev(mc, TYPE_PNV_PHB); } =20 -static void pnv_machine_power10_class_init(ObjectClass *oc, void *data) +static void pnv_machine_p10_common_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); PnvMachineClass *pmc =3D PNV_MACHINE_CLASS(oc); @@ -2263,7 +2263,6 @@ static void pnv_machine_power10_class_init(ObjectClas= s *oc, void *data) { TYPE_PNV_PHB_ROOT_PORT, "version", "5" }, }; =20 - mc->desc =3D "IBM PowerNV (Non-Virtualized) POWER10"; mc->default_cpu_type =3D POWERPC_CPU_TYPE_NAME("power10_v2.0"); compat_props_add(mc->compat_props, phb_compat, G_N_ELEMENTS(phb_compat= )); =20 @@ -2276,6 +2275,22 @@ static void pnv_machine_power10_class_init(ObjectCla= ss *oc, void *data) machine_class_allow_dynamic_sysbus_dev(mc, TYPE_PNV_PHB); } =20 +static void pnv_machine_power10_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + pnv_machine_p10_common_class_init(oc, data); + mc->desc =3D "IBM PowerNV (Non-Virtualized) POWER10"; +} + +static void pnv_machine_p10_rainier_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + pnv_machine_p10_common_class_init(oc, data); + mc->desc =3D "IBM PowerNV (Non-Virtualized) POWER10 Rainier"; +} + static bool pnv_machine_get_hb(Object *obj, Error **errp) { PnvMachineState *pnv =3D PNV_MACHINE(obj); @@ -2381,6 +2396,11 @@ static void pnv_machine_class_init(ObjectClass *oc, = void *data) } =20 static const TypeInfo types[] =3D { + { + .name =3D MACHINE_TYPE_NAME("powernv10-rainier"), + .parent =3D MACHINE_TYPE_NAME("powernv10"), + .class_init =3D pnv_machine_p10_rainier_class_init, + }, { .name =3D MACHINE_TYPE_NAME("powernv10"), .parent =3D TYPE_PNV_MACHINE, --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109117; cv=none; d=zohomail.com; s=zohoarc; b=mU+Jb48LK/UFM0bZdzSBttxQcZyQ/qdhW9CnBINz1bhmInBQKC5Icb9g83OMnE96QWPikTZxGhZxyvjpApaSYlKEUgApAwsyR0+KWn4TgGxQtwdsgkFHnlsktwZ6TOMxJAiLLvbm7A9/egb6+YOrvbljb/BtTH5OdHTqCjbnybI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109117; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YWifvySt7AmR8PugmJ/zCcmzouBXodoSp88/00wwxJ8=; b=Eb1Zxi7lnA1dKFtJdgBDDqy6dP3muufZd09yGGfJBgZnK3HC/oJugXlauDFo5UEc2ZkMINreQGVFh+ZiD1D7zL4jbAuN1m7WQPKSL41Xx6P+cdDDJ+bUwHRbv+4StL/+Xa/A83OUax1LOa41hCKGkIHqDOeGp4xKXmrccambn4o= 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 1701109117137190.15461660000153; Mon, 27 Nov 2023 10:18:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gBF-0001Yl-PQ; Mon, 27 Nov 2023 13:18:01 -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 ) id 1r7gBE-0001YW-N1; Mon, 27 Nov 2023 13:18:00 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gBD-00018u-4Y; Mon, 27 Nov 2023 13:18:00 -0500 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARIER1h027074; Mon, 27 Nov 2023 18:17:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un074r38a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:54 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARIFKWg029703; Mon, 27 Nov 2023 18:17:52 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un074r2yu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:52 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGtLKW018588; Mon, 27 Nov 2023 18:17:26 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([172.16.1.70]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ukwfjt50f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:26 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHPiD19464950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:25 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F0FAB58059; Mon, 27 Nov 2023 18:17:24 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C41F158058; Mon, 27 Nov 2023 18:17:24 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:24 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=YWifvySt7AmR8PugmJ/zCcmzouBXodoSp88/00wwxJ8=; b=nxBpyiHK50V0GB9ExTEZVN9Ij1+OLKl3BbCneg8CBmJmwFKblCKI1ZjPSd+wk1LTkPN4 V13BQ58ASr/51e/PA8XAvPVErVtDNpZpxm5x2X/7lmiH7otMmPN5/ED1fb6wPlpmLnBN It6GZiTVf6mRA4phebtqP2g2QYbOylY0RW/+KLAIE82V/wYJ3Kn3H6aY289Inz/nLrHq Qz4AEMVOeO8tPaSWCNN3ranuo/65k+VgjXB9zzFfwrXXGqOAn1nbPsM9wJKynQGmlxq/ hsnvN7od1aG3izojxYVyZ2nn4jJ8stqj6zAVBpGE56LaQVP8d2i+Ydj/c9RaTfvap1o/ nw== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab Subject: [PATCH v6 4/9] ppc/pnv: Add pca9552 to powernv10-rainier for PCIe hotplug power control Date: Mon, 27 Nov 2023 12:16:50 -0600 Message-Id: <20231127181655.1997496-5-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: WUJfBZYP2vwhKFBA_v4OwOdd89WgnxNW X-Proofpoint-ORIG-GUID: e_y53bhGxvwGf-1Hba7csxXonUYwS6Fx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.158.5; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109118261000022 The Power Hypervisor code expects to see a pca9552 device connected to the 3rd PNV I2C engine on port 1 at I2C address 0x63 (or left- justified address of 0xC6). This is used by hypervisor code to control PCIe slot power during hotplug events. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Glenn Miles --- No change from previous version hw/ppc/Kconfig | 1 + hw/ppc/pnv.c | 25 +++++++++++++++++++++++++ include/hw/ppc/pnv.h | 1 + 3 files changed, 27 insertions(+) diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig index 56f0475a8e..f77ca773cf 100644 --- a/hw/ppc/Kconfig +++ b/hw/ppc/Kconfig @@ -32,6 +32,7 @@ config POWERNV select XIVE select FDT_PPC select PCI_POWERNV + select PCA9552 =20 config PPC405 bool diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 08704ce695..d8d19fb065 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -790,6 +790,7 @@ static void pnv_init(MachineState *machine) const char *bios_name =3D machine->firmware ?: FW_FILE_NAME; PnvMachineState *pnv =3D PNV_MACHINE(machine); MachineClass *mc =3D MACHINE_GET_CLASS(machine); + PnvMachineClass *pmc =3D PNV_MACHINE_GET_CLASS(machine); char *fw_filename; long fw_size; uint64_t chip_ram_start =3D 0; @@ -979,6 +980,13 @@ static void pnv_init(MachineState *machine) */ pnv->powerdown_notifier.notify =3D pnv_powerdown_notify; qemu_register_powerdown_notifier(&pnv->powerdown_notifier); + + /* + * Create/Connect any machine-specific I2C devices + */ + if (pmc->i2c_init) { + pmc->i2c_init(pnv); + } } =20 /* @@ -1879,6 +1887,21 @@ static void pnv_chip_power10_realize(DeviceState *de= v, Error **errp) qdev_get_gpio_in(DEVICE(&chip10->psi), PSIHB9_IRQ_SBE_I2C)); } + +} + +static void pnv_rainier_i2c_init(PnvMachineState *pnv) +{ + int i; + for (i =3D 0; i < pnv->num_chips; i++) { + Pnv10Chip *chip10 =3D PNV10_CHIP(pnv->chips[i]); + + /* + * Add a PCA9552 I2C device for PCIe hotplug control + * to engine 2, bus 1, address 0x63 + */ + i2c_slave_create_simple(chip10->i2c[2].busses[1], "pca9552", 0x63); + } } =20 static uint32_t pnv_chip_power10_xscom_pcba(PnvChip *chip, uint64_t addr) @@ -2286,9 +2309,11 @@ static void pnv_machine_power10_class_init(ObjectCla= ss *oc, void *data) static void pnv_machine_p10_rainier_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); + PnvMachineClass *pmc =3D PNV_MACHINE_CLASS(oc); =20 pnv_machine_p10_common_class_init(oc, data); mc->desc =3D "IBM PowerNV (Non-Virtualized) POWER10 Rainier"; + pmc->i2c_init =3D pnv_rainier_i2c_init; } =20 static bool pnv_machine_get_hb(Object *obj, Error **errp) diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h index 7e5fef7c43..110ac9aace 100644 --- a/include/hw/ppc/pnv.h +++ b/include/hw/ppc/pnv.h @@ -76,6 +76,7 @@ struct PnvMachineClass { int compat_size; =20 void (*dt_power_mgt)(PnvMachineState *pnv, void *fdt); + void (*i2c_init)(PnvMachineState *pnv); }; =20 struct PnvMachineState { --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109145; cv=none; d=zohomail.com; s=zohoarc; b=lVvwBUI4YNu97vxQifLGTonwxrFP27A7m/6RNz5/VQPg4e44fqnRJFPIdUsoqrOXrIc+oRrNtaR9OTu6JCmkQpngt91A/SRIHPG20ln6ABGr78Z7b/QJpDLZx7IE9XGki/NJlVrhsKiX96NOpx/ZJFMHM5J87vqdaMaKrtaKmKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109145; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZgC1I8nOP1IWtgez8DvBdSGGXz8ZpWJd0sotXK22zuo=; b=TtlyI7OgWom3LqVib4HtyMaDMGXS4Qm/WIJK1kmExct5VZ9g0z96dC6/xDbc5YDQnDMBcbK7ksGl41eXBPh/EBEGc3rdXoE+0aaSdatCO/PcjL6OeF/8NvkRlE0znPqQZvfgCaF2d6KqyGUcUZ+4ZbVL1mDb+LlvxQ+UxIS5Lqo= 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 1701109145116589.4474517865979; Mon, 27 Nov 2023 10:19:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gBD-0001Y3-55; Mon, 27 Nov 2023 13:17:59 -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 ) id 1r7gBB-0001Wo-DL; Mon, 27 Nov 2023 13:17:57 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gB9-00018Z-Sb; Mon, 27 Nov 2023 13:17:57 -0500 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARIE5pH010487; Mon, 27 Nov 2023 18:17:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un077r39y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:52 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARIF2d1013125; Mon, 27 Nov 2023 18:17:51 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un077r31t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:51 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGoPwC016887; Mon, 27 Nov 2023 18:17:27 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uku8stsb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:27 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHQkc14287574 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:26 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7E39258058; Mon, 27 Nov 2023 18:17:26 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50F0858057; Mon, 27 Nov 2023 18:17:26 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:26 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=ZgC1I8nOP1IWtgez8DvBdSGGXz8ZpWJd0sotXK22zuo=; b=ePSgdERckQmkBmiOmvqULe0ZUCqq6IMNbEnsrO94tqjzjjHJjEYFsca7SHyaAo05mFst kzfyKrmsN6iFPElY0b0ceZ2ySoxkPscyECbf7fgWFLvIfxVb6P+0f6ljvD4jPUVGZkwc uGeq42sRZIjED0n/9xRs4EJZPsX9N0SCwtgdiE2JTCx3eSnRwoFsj490WiMGYKEVY93f VYi6rrQ32VOXqjM7XHQ8VYfFBoippaTjeNIilUNivV6YUkZ6ysIXDl5O1OtzbGTUY/3G 1ddxsNu6j8xvmbjIaCv520KD4p+6wJ6qte8eECh6NqE1N1YNBz3d+xvVjYqd8Nrg5cXe yw== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab Subject: [PATCH v6 5/9] ppc/pnv: Wire up pca9552 GPIO pins for PCIe hotplug power control Date: Mon, 27 Nov 2023 12:16:51 -0600 Message-Id: <20231127181655.1997496-6-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: C1kEyScSQYiC4ZUuG5O2JoTX94k_MZ45 X-Proofpoint-ORIG-GUID: a5CzExKJTVxzr-RS-P1FkqF1RFy7y0Hx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 clxscore=1015 bulkscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.158.5; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109146892000001 For power10-rainier, a pca9552 device is used for PCIe slot hotplug power control by the Power Hypervisor code. The code expects that some time after it enables power to a PCIe slot by asserting one of the pca9552 GPIO pins 0-4, it should see a "power good" signal asserted on one of pca9552 GPIO pins 5-9. To simulate this behavior, we simply connect the GPIO outputs for pins 0-4 to the GPIO inputs for pins 5-9. Each PCIe slot is assigned 3 GPIO pins on the pca9552 device, for control of up to 5 PCIe slots. The per-slot signal names are: SLOTx_EN.......PHYP uses this as an output to enable slot power. We connect this to the SLOTx_PG pin to simulate a PGOOD signal. SLOTx_PG.......PHYP uses this as in input to detect PGOOD for the slot. For our purposes we just connect this to the SLOTx_EN output. SLOTx_Control..PHYP uses this as an output to prevent a race condition in the real hotplug circuitry, but we can ignore this output for simulation. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Glenn Miles --- Changes from previous version: - Changed 'hotplug' variable name to 'dev' hw/ppc/pnv.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index d8d19fb065..42105211f5 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -1900,7 +1900,19 @@ static void pnv_rainier_i2c_init(PnvMachineState *pn= v) * Add a PCA9552 I2C device for PCIe hotplug control * to engine 2, bus 1, address 0x63 */ - i2c_slave_create_simple(chip10->i2c[2].busses[1], "pca9552", 0x63); + I2CSlave *dev =3D i2c_slave_create_simple(chip10->i2c[2].busses[1], + "pca9552", 0x63); + + /* + * Connect PCA9552 GPIO pins 0-4 (SLOTx_EN) outputs to GPIO pins 5= -9 + * (SLOTx_PG) inputs in order to fake the pgood state of PCIe slots + * after hypervisor code sets a SLOTx_EN pin high. + */ + qdev_connect_gpio_out(DEVICE(dev), 0, qdev_get_gpio_in(DEVICE(dev)= , 5)); + qdev_connect_gpio_out(DEVICE(dev), 1, qdev_get_gpio_in(DEVICE(dev)= , 6)); + qdev_connect_gpio_out(DEVICE(dev), 2, qdev_get_gpio_in(DEVICE(dev)= , 7)); + qdev_connect_gpio_out(DEVICE(dev), 3, qdev_get_gpio_in(DEVICE(dev)= , 8)); + qdev_connect_gpio_out(DEVICE(dev), 4, qdev_get_gpio_in(DEVICE(dev)= , 9)); } } =20 --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109164; cv=none; d=zohomail.com; s=zohoarc; b=IKl+9KOtKrCESuWqWx0ER7/PwuQFEJSbWXpof2piKERUlH1j0Rn5KIKpEIfcYNUiot2iuqTEQ3acR0RmQH3PRHAJOk0kMC8uXBmwDWsXUH4wcBpQR+qTNqGNaD2dQNJyy+txXW36d+g5ZPW5ryVMyKO6fj7b3Jzn902ix3aqVoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109164; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nkgGlxqg8UV1SVlvWw8rs6SNQoIvMdJKthxnyYmZuwU=; b=ILGzQqUGDcxqtUjyadGQLCIN6GENj9ouvghtfkPlGUnueN5QHwTnmLSXL4Yu/SeneAVmBzMG5do9Qiw3S9Div+OO6kgGAdtqKf7RxVFor4y1tAOdwH2YzJ0Rp2+yq5MmdFO7SA7LngNWzj3t+saSXDH4a7/VKIMUlWCUGxCbUXM= 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 1701109164331128.19504937870352; Mon, 27 Nov 2023 10:19:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gBC-0001XN-AV; Mon, 27 Nov 2023 13:17:58 -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 ) id 1r7gBA-0001Wc-Lk; Mon, 27 Nov 2023 13:17:56 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gB9-00018S-7m; Mon, 27 Nov 2023 13:17:56 -0500 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARIE4oI010407; Mon, 27 Nov 2023 18:17:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un077r39r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:51 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARIEpP8012873; Mon, 27 Nov 2023 18:17:51 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un077r32k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:51 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGtR5n009198; Mon, 27 Nov 2023 18:17:29 GMT Received: from smtprelay05.dal12v.mail.ibm.com ([172.16.1.7]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ukumyaph7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:29 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay05.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHSiY24380044 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:28 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1508958058; Mon, 27 Nov 2023 18:17:28 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBDC658057; Mon, 27 Nov 2023 18:17:27 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:27 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=nkgGlxqg8UV1SVlvWw8rs6SNQoIvMdJKthxnyYmZuwU=; b=K9B9FGMFCQlJccM3uEAaAyyHw7C19mk/LZJjcbEW8dwwnv/NIwN9ThBajosX4Yu+5FIt RVrMzcg2I37J7VNpJz5bWhICYr/AtRMwNXLgHZul/WeMfWhHI1S5vO5d0Ka25iRWgGwp klyVOCznm7mmdS46pGBOCmZYRGoDuJldnuLScjCxkB00/0EpAd34DMNaTI0F+L8Y5lCj 2aQHyQLg3C6ZrilWDj3J282Qsr0tagV3zkwTPSyGwozfCufzCRn8kau9wk3oXjj9WTnA Xqy27bplK/2qwNCBtFTophshoWSx9c3MuL1Na2MHVhwkZgDMJRFiD7GpexGxvgIDn2BP Zw== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab Subject: [PATCH v6 6/9] ppc/pnv: Use resettable interface to reset child I2C buses Date: Mon, 27 Nov 2023 12:16:52 -0600 Message-Id: <20231127181655.1997496-7-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: LXhuv4HZNFfEza4UJxqzFcfPjXrra-qB X-Proofpoint-ORIG-GUID: SBFlI2esIkUzoEIPFpc0lLDVh25pAWRi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 clxscore=1015 bulkscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=736 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.158.5; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109165321000001 The QEMU I2C buses and devices use the resettable interface for resetting while the PNV I2C controller and parent buses and devices have not yet transitioned to this new interface and use the old reset strategy. This was preventing the I2C buses and devices wired to the PNV I2C controller from being reset. The short term fix for this is to have the PNV I2C Controller's reset function explicitly call the resettable interface function, bus_cold_reset(), on all child I2C buses. The long term fix should be to transition all PNV parent devices and buses to use the resettable interface so that all child buses and devices are automatically reset. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Glenn Miles --- No change from previous version hw/ppc/pnv_i2c.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/ppc/pnv_i2c.c b/hw/ppc/pnv_i2c.c index 656a48eebe..774946d6b2 100644 --- a/hw/ppc/pnv_i2c.c +++ b/hw/ppc/pnv_i2c.c @@ -629,6 +629,19 @@ static int pnv_i2c_dt_xscom(PnvXScomInterface *dev, vo= id *fdt, return 0; } =20 +static void pnv_i2c_sys_reset(void *dev) +{ + int port; + PnvI2C *i2c =3D PNV_I2C(dev); + + pnv_i2c_reset(dev); + + /* reset all buses connected to this i2c controller */ + for (port =3D 0; port < i2c->num_busses; port++) { + bus_cold_reset(BUS(i2c->busses[port])); + } +} + static void pnv_i2c_realize(DeviceState *dev, Error **errp) { PnvI2C *i2c =3D PNV_I2C(dev); @@ -654,7 +667,7 @@ static void pnv_i2c_realize(DeviceState *dev, Error **e= rrp) =20 fifo8_create(&i2c->fifo, PNV_I2C_FIFO_SIZE); =20 - qemu_register_reset(pnv_i2c_reset, dev); + qemu_register_reset(pnv_i2c_sys_reset, dev); =20 qdev_init_gpio_out(DEVICE(dev), &i2c->psi_irq, 1); } --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109203; cv=none; d=zohomail.com; s=zohoarc; b=cEou7qwHgf6c8qqSxuxornen3Bnxqy4yXMY4VVexQCT3T+GJOwZiAuR3Wfvd8jsNDygJ5P3vaeSK4UfHoSuQXE6lRIl9QmJMrGHPoWM32fhyXlGVMBLeCGA8TCRsjX3hdBRv6xWAJiZ7T7HN+Xufh39iyhM8YS0oYfFrWA6TW30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109203; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pQV90ZRKVYwO98zBI4/yNwwdSzM5zUsWtbFwBcrJZhM=; b=c1Rv6JyXotq07bqLDesON6UoBrKdfR/px1tK6I6ullRuMTEV2YUjHSV7pT1GKPmNhVbIGBBYoVLO9L8WgpFr1jIXbMN9ZXIIGHTtt8kQFZdlrJLqD+nIyZ8uLoo33mKYnmm9I9jKyoubHQCb0ZXNUxIzo+CDdDzprGktnkUZ/P4= 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 1701109203782730.3022842404791; Mon, 27 Nov 2023 10:20:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gCk-0004ii-Jt; Mon, 27 Nov 2023 13:19:34 -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 ) id 1r7gCi-0004TM-B7; Mon, 27 Nov 2023 13:19:32 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gCe-0001L6-Pv; Mon, 27 Nov 2023 13:19:32 -0500 Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARHaHbs009860; Mon, 27 Nov 2023 18:19:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umy9j2375-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:19:25 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARHaOFR010819; Mon, 27 Nov 2023 18:19:23 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umy9j22fu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:19:23 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGw5VO001736; Mon, 27 Nov 2023 18:17:31 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ukwy1j0gy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:31 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHUbD9110050 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:30 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8BA9B58058; Mon, 27 Nov 2023 18:17:30 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 586CE58057; Mon, 27 Nov 2023 18:17:30 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:30 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=pp1; bh=pQV90ZRKVYwO98zBI4/yNwwdSzM5zUsWtbFwBcrJZhM=; b=fY3gDDZS8B9w5x7R96OgC9rj9BR7pQLcwVKIb0CAhSsC4J/TkRGi+0oTHnHTs6XoWz6Y YSDNyo5uUASNnpacZ2nHrFGvuSkpW6Xunti0uCrB7nz93ThfHjxtHc0WDFkVv2qNTJoi rrYFEAIUvwYqoKskAm9o/ft2Wjd46zVbsYEkh2Gxz0t02PgBywK/TLS6+bKbAgkgxZ+6 H75bu2nyHPMaStSZ7xvZ5ESUxRmqatXtlA0dzbGTGR8TOmmzljEiP6YHEon3cdSo5Esa ARFveaDGhAbSowQCxaqhMKP0YGQqlVZTK7U/QCC+vwrrh7ds3G++cIVLxhUb/t4UBcBI 1w== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab Subject: [PATCH v6 7/9] misc: Add a pca9554 GPIO device model Date: Mon, 27 Nov 2023 12:16:53 -0600 Message-Id: <20231127181655.1997496-8-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> Content-Type: text/plain; charset="utf-8" X-TM-AS-GCONF: 00 X-Proofpoint-GUID: GTz1Pg2qX4ZbApal1Adm86U10Y8kLocw X-Proofpoint-ORIG-GUID: HgfsPTdYtOJEBLwBTezbAN2xYFS0N9SI Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 impostorscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.158.5; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109204335000001 Specs are available here: https://www.nxp.com/docs/en/data-sheet/PCA9554_9554A.pdf This is a simple model supporting the basic registers for GPIO mode. The device also supports an interrupt output line but the model does not yet support this. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Glenn Miles --- No change from previous version MAINTAINERS | 10 +- hw/misc/pca9554.c | 328 +++++++++++++++++++++++++++++++++ include/hw/misc/pca9554.h | 36 ++++ include/hw/misc/pca9554_regs.h | 19 ++ 4 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 hw/misc/pca9554.c create mode 100644 include/hw/misc/pca9554.h create mode 100644 include/hw/misc/pca9554_regs.h diff --git a/MAINTAINERS b/MAINTAINERS index 695e0bd34f..4d1c991691 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1155,9 +1155,7 @@ R: Joel Stanley L: qemu-arm@nongnu.org S: Maintained F: hw/*/*aspeed* -F: hw/misc/pca9552.c F: include/hw/*/*aspeed* -F: include/hw/misc/pca9552*.h F: hw/net/ftgmac100.c F: include/hw/net/ftgmac100.h F: docs/system/arm/aspeed.rst @@ -1526,6 +1524,14 @@ F: include/hw/pci-host/pnv* F: pc-bios/skiboot.lid F: tests/qtest/pnv* =20 +pca955x +M: Glenn Miles +L: qemu-ppc@nongnu.org +L: qemu-arm@nongnu.org +S: Odd Fixes +F: hw/misc/pca955*.c +F: include/hw/misc/pca955*.h + virtex_ml507 M: Edgar E. Iglesias L: qemu-ppc@nongnu.org diff --git a/hw/misc/pca9554.c b/hw/misc/pca9554.c new file mode 100644 index 0000000000..778b32e443 --- /dev/null +++ b/hw/misc/pca9554.c @@ -0,0 +1,328 @@ +/* + * PCA9554 I/O port + * + * Copyright (c) 2023, IBM Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/bitops.h" +#include "hw/qdev-properties.h" +#include "hw/misc/pca9554.h" +#include "hw/misc/pca9554_regs.h" +#include "hw/irq.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "trace.h" +#include "qom/object.h" + +struct PCA9554Class { + /*< private >*/ + I2CSlaveClass parent_class; + /*< public >*/ +}; +typedef struct PCA9554Class PCA9554Class; + +DECLARE_CLASS_CHECKERS(PCA9554Class, PCA9554, + TYPE_PCA9554) + +#define PCA9554_PIN_LOW 0x0 +#define PCA9554_PIN_HIZ 0x1 + +static const char *pin_state[] =3D {"low", "high"}; + +static void pca9554_update_pin_input(PCA9554State *s) +{ + int i; + uint8_t config =3D s->regs[PCA9554_CONFIG]; + uint8_t output =3D s->regs[PCA9554_OUTPUT]; + uint8_t internal_state =3D config | output; + + for (i =3D 0; i < PCA9554_PIN_COUNT; i++) { + uint8_t bit_mask =3D 1 << i; + uint8_t internal_pin_state =3D (internal_state >> i) & 0x1; + uint8_t old_value =3D s->regs[PCA9554_INPUT] & bit_mask; + uint8_t new_value; + + switch (internal_pin_state) { + case PCA9554_PIN_LOW: + s->regs[PCA9554_INPUT] &=3D ~bit_mask; + break; + case PCA9554_PIN_HIZ: + /* + * pullup sets it to a logical 1 unless + * external device drives it low. + */ + if (s->ext_state[i] =3D=3D PCA9554_PIN_LOW) { + s->regs[PCA9554_INPUT] &=3D ~bit_mask; + } else { + s->regs[PCA9554_INPUT] |=3D bit_mask; + } + break; + default: + break; + } + + /* update irq state only if pin state changed */ + new_value =3D s->regs[PCA9554_INPUT] & bit_mask; + if (new_value !=3D old_value) { + if (new_value) { + /* changed from 0 to 1 */ + qemu_set_irq(s->gpio_out[i], 1); + } else { + /* changed from 1 to 0 */ + qemu_set_irq(s->gpio_out[i], 0); + } + } + } +} + +static uint8_t pca9554_read(PCA9554State *s, uint8_t reg) +{ + switch (reg) { + case PCA9554_INPUT: + return s->regs[PCA9554_INPUT] ^ s->regs[PCA9554_POLARITY]; + case PCA9554_OUTPUT: + case PCA9554_POLARITY: + case PCA9554_CONFIG: + return s->regs[reg]; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: unexpected read to register %d= \n", + __func__, reg); + return 0xFF; + } +} + +static void pca9554_write(PCA9554State *s, uint8_t reg, uint8_t data) +{ + switch (reg) { + case PCA9554_OUTPUT: + case PCA9554_CONFIG: + s->regs[reg] =3D data; + pca9554_update_pin_input(s); + break; + case PCA9554_POLARITY: + s->regs[reg] =3D data; + break; + case PCA9554_INPUT: + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: unexpected write to register %= d\n", + __func__, reg); + } +} + +static uint8_t pca9554_recv(I2CSlave *i2c) +{ + PCA9554State *s =3D PCA9554(i2c); + uint8_t ret; + + ret =3D pca9554_read(s, s->pointer & 0x3); + + return ret; +} + +static int pca9554_send(I2CSlave *i2c, uint8_t data) +{ + PCA9554State *s =3D PCA9554(i2c); + + /* First byte sent by is the register address */ + if (s->len =3D=3D 0) { + s->pointer =3D data; + s->len++; + } else { + pca9554_write(s, s->pointer & 0x3, data); + } + + return 0; +} + +static int pca9554_event(I2CSlave *i2c, enum i2c_event event) +{ + PCA9554State *s =3D PCA9554(i2c); + + s->len =3D 0; + return 0; +} + +static void pca9554_get_pin(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCA9554State *s =3D PCA9554(obj); + int pin, rc; + uint8_t state; + + rc =3D sscanf(name, "pin%2d", &pin); + if (rc !=3D 1) { + error_setg(errp, "%s: error reading %s", __func__, name); + return; + } + if (pin < 0 || pin > PCA9554_PIN_COUNT) { + error_setg(errp, "%s invalid pin %s", __func__, name); + return; + } + + state =3D pca9554_read(s, PCA9554_CONFIG); + state |=3D pca9554_read(s, PCA9554_OUTPUT); + state =3D (state >> pin) & 0x1; + visit_type_str(v, name, (char **)&pin_state[state], errp); +} + +static void pca9554_set_pin(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCA9554State *s =3D PCA9554(obj); + int pin, rc, val; + uint8_t state, mask; + char *state_str; + + if (!visit_type_str(v, name, &state_str, errp)) { + return; + } + rc =3D sscanf(name, "pin%2d", &pin); + if (rc !=3D 1) { + error_setg(errp, "%s: error reading %s", __func__, name); + return; + } + if (pin < 0 || pin > PCA9554_PIN_COUNT) { + error_setg(errp, "%s invalid pin %s", __func__, name); + return; + } + + for (state =3D 0; state < ARRAY_SIZE(pin_state); state++) { + if (!strcmp(state_str, pin_state[state])) { + break; + } + } + if (state >=3D ARRAY_SIZE(pin_state)) { + error_setg(errp, "%s invalid pin state %s", __func__, state_str); + return; + } + + /* First, modify the output register bit */ + val =3D pca9554_read(s, PCA9554_OUTPUT); + mask =3D 0x1 << pin; + if (state =3D=3D PCA9554_PIN_LOW) { + val &=3D ~(mask); + } else { + val |=3D mask; + } + pca9554_write(s, PCA9554_OUTPUT, val); + + /* Then, clear the config register bit for output mode */ + val =3D pca9554_read(s, PCA9554_CONFIG); + val &=3D ~mask; + pca9554_write(s, PCA9554_CONFIG, val); +} + +static const VMStateDescription pca9554_vmstate =3D { + .name =3D "PCA9554", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(len, PCA9554State), + VMSTATE_UINT8(pointer, PCA9554State), + VMSTATE_UINT8_ARRAY(regs, PCA9554State, PCA9554_NR_REGS), + VMSTATE_UINT8_ARRAY(ext_state, PCA9554State, PCA9554_PIN_COUNT), + VMSTATE_I2C_SLAVE(i2c, PCA9554State), + VMSTATE_END_OF_LIST() + } +}; + +static void pca9554_reset(DeviceState *dev) +{ + PCA9554State *s =3D PCA9554(dev); + + s->regs[PCA9554_INPUT] =3D 0xFF; + s->regs[PCA9554_OUTPUT] =3D 0xFF; + s->regs[PCA9554_POLARITY] =3D 0x0; /* No pins are inverted */ + s->regs[PCA9554_CONFIG] =3D 0xFF; /* All pins are inputs */ + + memset(s->ext_state, PCA9554_PIN_HIZ, PCA9554_PIN_COUNT); + pca9554_update_pin_input(s); + + s->pointer =3D 0x0; + s->len =3D 0; +} + +static void pca9554_initfn(Object *obj) +{ + int pin; + + for (pin =3D 0; pin < PCA9554_PIN_COUNT; pin++) { + char *name; + + name =3D g_strdup_printf("pin%d", pin); + object_property_add(obj, name, "bool", pca9554_get_pin, pca9554_se= t_pin, + NULL, NULL); + g_free(name); + } +} + +static void pca9554_set_ext_state(PCA9554State *s, int pin, int level) +{ + if (s->ext_state[pin] !=3D level) { + s->ext_state[pin] =3D level; + pca9554_update_pin_input(s); + } +} + +static void pca9554_gpio_in_handler(void *opaque, int pin, int level) +{ + + PCA9554State *s =3D PCA9554(opaque); + + assert((pin >=3D 0) && (pin < PCA9554_PIN_COUNT)); + pca9554_set_ext_state(s, pin, level); +} + +static void pca9554_realize(DeviceState *dev, Error **errp) +{ + PCA9554State *s =3D PCA9554(dev); + + if (!s->description) { + s->description =3D g_strdup("pca9554"); + } + + qdev_init_gpio_out(dev, s->gpio_out, PCA9554_PIN_COUNT); + qdev_init_gpio_in(dev, pca9554_gpio_in_handler, PCA9554_PIN_COUNT); +} + +static Property pca9554_properties[] =3D { + DEFINE_PROP_STRING("description", PCA9554State, description), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pca9554_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + I2CSlaveClass *k =3D I2C_SLAVE_CLASS(klass); + + k->event =3D pca9554_event; + k->recv =3D pca9554_recv; + k->send =3D pca9554_send; + dc->realize =3D pca9554_realize; + dc->reset =3D pca9554_reset; + dc->vmsd =3D &pca9554_vmstate; + device_class_set_props(dc, pca9554_properties); +} + +static const TypeInfo pca9554_info =3D { + .name =3D TYPE_PCA9554, + .parent =3D TYPE_I2C_SLAVE, + .instance_init =3D pca9554_initfn, + .instance_size =3D sizeof(PCA9554State), + .class_init =3D pca9554_class_init, + .class_size =3D sizeof(PCA9554Class), + .abstract =3D false, +}; + +static void pca9554_register_types(void) +{ + type_register_static(&pca9554_info); +} + +type_init(pca9554_register_types) diff --git a/include/hw/misc/pca9554.h b/include/hw/misc/pca9554.h new file mode 100644 index 0000000000..54bfc4c4c7 --- /dev/null +++ b/include/hw/misc/pca9554.h @@ -0,0 +1,36 @@ +/* + * PCA9554 I/O port + * + * Copyright (c) 2023, IBM Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef PCA9554_H +#define PCA9554_H + +#include "hw/i2c/i2c.h" +#include "qom/object.h" + +#define TYPE_PCA9554 "pca9554" +typedef struct PCA9554State PCA9554State; +DECLARE_INSTANCE_CHECKER(PCA9554State, PCA9554, + TYPE_PCA9554) + +#define PCA9554_NR_REGS 4 +#define PCA9554_PIN_COUNT 8 + +struct PCA9554State { + /*< private >*/ + I2CSlave i2c; + /*< public >*/ + + uint8_t len; + uint8_t pointer; + + uint8_t regs[PCA9554_NR_REGS]; + qemu_irq gpio_out[PCA9554_PIN_COUNT]; + uint8_t ext_state[PCA9554_PIN_COUNT]; + char *description; /* For debugging purpose only */ +}; + +#endif diff --git a/include/hw/misc/pca9554_regs.h b/include/hw/misc/pca9554_regs.h new file mode 100644 index 0000000000..602c4a90e0 --- /dev/null +++ b/include/hw/misc/pca9554_regs.h @@ -0,0 +1,19 @@ +/* + * PCA9554 I/O port registers + * + * Copyright (c) 2023, IBM Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef PCA9554_REGS_H +#define PCA9554_REGS_H + +/* + * Bits [0:1] are used to address a specific register. + */ +#define PCA9554_INPUT 0 /* read only input register */ +#define PCA9554_OUTPUT 1 /* read/write pin output state */ +#define PCA9554_POLARITY 2 /* Set polarity of input register */ +#define PCA9554_CONFIG 3 /* Set pins as inputs our ouputs */ + +#endif --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109134; cv=none; d=zohomail.com; s=zohoarc; b=kdixIeAJh/NElfzoi+cRGZbphQjrLVMHIj44AOYcFIb1qnxU8r5UVqAVIEDFsDne1JUau0Kh6vCVqBo5zn/rW7ywlX6sQugdPVyx1aUssau29Xq0C1H4/fekRCL/aDlmgPym63s0dqEx8KVU6Ir9ldMGJl+xtINr09kTp90ARLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109134; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XEW3LRmfTpvWfcM4qLIvidW55TosnU+mL+5uHcchlC0=; b=dGCwZQjhGsEV/aAaO0x0kqRiRYyObVVvnaG9I5Yk0pBF8/dxdahBzOr8+tWYTl8JN2+sg2qnKq6OBLwoNO/ncVkzefVcWJhbC3tjbM4yvdhiOrpBmyjLE52Jg3smh6HaK4+IIY+Vs2mHsmWZoKV7BGvQQdXq5MSqq4zP7rxaJgA= 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 1701109134737424.52713583535115; Mon, 27 Nov 2023 10:18:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gB1-0001V2-Pw; Mon, 27 Nov 2023 13:17:47 -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 ) id 1r7gB0-0001UH-46; Mon, 27 Nov 2023 13:17:46 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gAv-00017m-UL; Mon, 27 Nov 2023 13:17:45 -0500 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARHmrwb005592; Mon, 27 Nov 2023 18:17:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umwynmtat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:37 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARH9s2S009902; Mon, 27 Nov 2023 18:17:36 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umwynmta9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:36 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGsDEs009572; Mon, 27 Nov 2023 18:17:35 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ukv8nagdd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:35 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHYV727984492 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:35 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 92BD658058; Mon, 27 Nov 2023 18:17:34 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6420A58057; Mon, 27 Nov 2023 18:17:34 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:34 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=XEW3LRmfTpvWfcM4qLIvidW55TosnU+mL+5uHcchlC0=; b=ZwirGriVa87Ck2j/x7huu+TVuw0uiulNPSSg7ivzXvN+b8isZeH6HNU1aQ/GvezJXDbd iOtwKHx5hsUk1ETuhJok8eMBhf9OR5BWLjPwz/xNHMPYDCinwcD288AprJl09JKpMpSt Fk+pRq2JMf4ZEy9xG/AiyCQnMrtKdfW3wghesXRTlmaQY3J7GXBfSK9LCbPh7fi8HoZI wxJUL2iMzDkq2JWcUSegABhSRy7LDWSkKpM+AmoJn3OJWtBApdFUvZHLsgJqsUAVETDE 5CVXOhxp9o48dn9Ku3CczQztTCKJFH0j7Y7RcfMuMVkNmrVddj43WB1LVauI1rN7kJOQ 7Q== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab Subject: [PATCH v6 8/9] ppc/pnv: Add a pca9554 I2C device to powernv10-rainier Date: Mon, 27 Nov 2023 12:16:54 -0600 Message-Id: <20231127181655.1997496-9-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: loR1nzAu-D6Jlc7bJvaqBkoIJB9OMNja X-Proofpoint-ORIG-GUID: k8bHfct1ThCUmjlOAK0lZC6pd480LFLt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.156.1; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109136598000001 For powernv10-rainier, the Power Hypervisor code expects to see a pca9554 device connected to the 3rd PNV I2C engine on port 1 at I2C address 0x25 (or left-justified address of 0x4A). This is used by the hypervisor code to detect if a "Cable Card" is present. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Glenn Miles --- No change from previous version hw/misc/Kconfig | 4 ++++ hw/misc/meson.build | 1 + hw/ppc/Kconfig | 1 + hw/ppc/pnv.c | 6 ++++++ 4 files changed, 12 insertions(+) diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index cc8a8c1418..c347a132c2 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -34,6 +34,10 @@ config PCA9552 bool depends on I2C =20 +config PCA9554 + bool + depends on I2C + config I2C_ECHO bool default y if TEST_DEVICES diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 36c20d5637..c39410e4a7 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -4,6 +4,7 @@ system_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('vm= coreinfo.c')) system_ss.add(when: 'CONFIG_ISA_DEBUG', if_true: files('debugexit.c')) system_ss.add(when: 'CONFIG_ISA_TESTDEV', if_true: files('pc-testdev.c')) system_ss.add(when: 'CONFIG_PCA9552', if_true: files('pca9552.c')) +system_ss.add(when: 'CONFIG_PCA9554', if_true: files('pca9554.c')) system_ss.add(when: 'CONFIG_PCI_TESTDEV', if_true: files('pci-testdev.c')) system_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c')) system_ss.add(when: 'CONFIG_EMPTY_SLOT', if_true: files('empty_slot.c')) diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig index f77ca773cf..2302778265 100644 --- a/hw/ppc/Kconfig +++ b/hw/ppc/Kconfig @@ -33,6 +33,7 @@ config POWERNV select FDT_PPC select PCI_POWERNV select PCA9552 + select PCA9554 =20 config PPC405 bool diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 42105211f5..40f6b8fea0 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -1913,6 +1913,12 @@ static void pnv_rainier_i2c_init(PnvMachineState *pn= v) qdev_connect_gpio_out(DEVICE(dev), 2, qdev_get_gpio_in(DEVICE(dev)= , 7)); qdev_connect_gpio_out(DEVICE(dev), 3, qdev_get_gpio_in(DEVICE(dev)= , 8)); qdev_connect_gpio_out(DEVICE(dev), 4, qdev_get_gpio_in(DEVICE(dev)= , 9)); + + /* + * Add a PCA9554 I2C device for cable card presence detection + * to engine 2, bus 1, address 0x25 + */ + i2c_slave_create_simple(chip10->i2c[2].busses[1], "pca9554", 0x25); } } =20 --=20 2.31.1 From nobody Wed Nov 27 02:20:08 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=linux.vnet.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1701109291; cv=none; d=zohomail.com; s=zohoarc; b=cKAY1uWDfFzaNNF93EBgWZL1b3CpqF+kHPRgOJnzcnJKz5BgaiOuz8ipn+/tbz4KFb5bwGea2g0sG1b5an53g5N4GHNcgGQ3zIq/Fb5AYx/PgYxne9vv6k0thAH5Qo9UY93Fmst1/F3NdUu95znBr/JwfaOe022vszTJ4XGZegc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109291; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=unhYqV701VehkEy56+EYu8++tvpvqJKm+MCh9R14TnA=; b=YO2tGUmVVoJZJMzJ9F9hqVu6QgSFGmJUfSYTyVt/jIWax2HJ5126NTZWwzycKa6ksi8R2X0HpNOWMI501CIiyKqwB4yR9AVKBE2DbdHLPTP30frMjoxOPSywyd1vw3RH6hR7+yooDEddi0gzqnyn+5GvA+kR7xv9MEasibX4LXg= 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 1701109291383528.3928050873582; Mon, 27 Nov 2023 10:21:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gEY-0007hs-IK; Mon, 27 Nov 2023 13:21:26 -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 ) id 1r7gEV-0007h1-PR; Mon, 27 Nov 2023 13:21:23 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7gER-0001ld-IM; Mon, 27 Nov 2023 13:21:23 -0500 Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARILC7j029226; Mon, 27 Nov 2023 18:21:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umxd544n8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:21:15 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARILCwb029248; Mon, 27 Nov 2023 18:21:12 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3umxd5440a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:21:11 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARGsxIJ025594; Mon, 27 Nov 2023 18:17:38 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ukvrkacfb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 18:17:38 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARIHbtw5243544 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 18:17:37 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 436CF5805D; Mon, 27 Nov 2023 18:17:37 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 06B6C58059; Mon, 27 Nov 2023 18:17:37 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 18:17:36 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=unhYqV701VehkEy56+EYu8++tvpvqJKm+MCh9R14TnA=; b=hf4xkicJi/ufDFw4rNzGisAbu7nDMxI/bDx5CTJYnlp4bzSKscHUL2o/1GaygtNSoAeV rWAmPApDJz/GOncznimITh5040/fPf+ozqUoWar7cVCwiD6W9tXBc9/H6XelgyXngXaT eYn7Fe8X2lFRWAqBbHAn80XwXR2nhsPbcXYIIafDADsiZkeqe7BXut2yKOXlUlV6y7Ao gfPo1s0cMx/jzK2qXbbE2dqeyyxSjx8T+Kh1iqpEaFhfVSbJP7cL8CAIpucvvZw1tZ0A rorEj9yGb3CYtBtBtph66tTWyb/UaM87734Junehu6cbllchnQ4fCRbXUcZE6SjIArg2 AA== From: Glenn Miles To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Glenn Miles , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Nicholas Piggin , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Reza Arbab Subject: [PATCH v6 9/9] ppc/pnv: Test pnv i2c master and connected devices Date: Mon, 27 Nov 2023 12:16:55 -0600 Message-Id: <20231127181655.1997496-10-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> References: <20231127181655.1997496-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: rC-KXQfKFqFESwprNRaEOTcsFtgJkctc X-Proofpoint-ORIG-GUID: YLVZQ1xujdAe7KXbJBEjMMM9Dk9ij6Ja X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_16,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1015 bulkscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270126 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: none client-ip=148.163.158.5; envelope-from=milesg@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @ibm.com) X-ZM-MESSAGEID: 1701109292543000001 Content-Type: text/plain; charset="utf-8" Tests the following for both P9 and P10: - I2C master POR status - I2C master status after immediate reset Tests the following for powernv10-ranier only: - Config pca9552 hotplug device pins as inputs then Read the INPUT0/1 registers to verify all pins are high - Connected GPIO pin tests of P10 PCA9552 device. Tests output of pins 0-4 affect input of pins 5-9 respectively. - PCA9554 GPIO pins test. Tests input and ouput functionality. Signed-off-by: Glenn Miles Reviewed-by: C=C3=A9dric Le Goater --- No change from previous version tests/qtest/meson.build | 1 + tests/qtest/pnv-host-i2c-test.c | 650 ++++++++++++++++++++++++++++++++ 2 files changed, 651 insertions(+) create mode 100644 tests/qtest/pnv-host-i2c-test.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 47dabf91d0..fbb0bd204c 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -163,6 +163,7 @@ qtests_ppc64 =3D \ qtests_ppc + \ (config_all_devices.has_key('CONFIG_PSERIES') ? ['device-plug-test'] : [= ]) + \ (config_all_devices.has_key('CONFIG_POWERNV') ? ['pnv-xscom-test'] : [])= + \ + (config_all_devices.has_key('CONFIG_POWERNV') ? ['pnv-host-i2c-test'] : = []) + \ (config_all_devices.has_key('CONFIG_PSERIES') ? ['rtas-test'] : []) + = \ (slirp.found() ? ['pxe-test'] : []) + \ (config_all_devices.has_key('CONFIG_USB_UHCI') ? ['usb-hcd-uhci-test'] := []) + \ diff --git a/tests/qtest/pnv-host-i2c-test.c b/tests/qtest/pnv-host-i2c-tes= t.c new file mode 100644 index 0000000000..377525e458 --- /dev/null +++ b/tests/qtest/pnv-host-i2c-test.c @@ -0,0 +1,650 @@ +/* + * QTest testcase for PowerNV 10 Host I2C Communications + * + * Copyright (c) 2023, 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 "libqtest.h" +#include "hw/misc/pca9554_regs.h" +#include "hw/misc/pca9552_regs.h" + +#define PPC_BIT(bit) (0x8000000000000000ULL >> (bit)) +#define PPC_BIT32(bit) (0x80000000 >> (bit)) +#define PPC_BIT8(bit) (0x80 >> (bit)) +#define PPC_BITMASK(bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITMASK32(bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ + PPC_BIT32(bs)) + +#define MASK_TO_LSH(m) (__builtin_ffsll(m) - 1) +#define GETFIELD(m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD(m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +#define P10_XSCOM_BASE 0x000603fc00000000ull +#define PNV10_CHIP_MAX_I2C 5 +#define PNV10_XSCOM_I2CM_BASE 0xa0000 +#define PNV10_XSCOM_I2CM_SIZE 0x1000 + +/* I2C FIFO register */ +#define I2C_FIFO_REG 0x4 +#define I2C_FIFO PPC_BITMASK(0, 7) + +/* I2C command register */ +#define I2C_CMD_REG 0x5 +#define I2C_CMD_WITH_START PPC_BIT(0) +#define I2C_CMD_WITH_ADDR PPC_BIT(1) +#define I2C_CMD_READ_CONT PPC_BIT(2) +#define I2C_CMD_WITH_STOP PPC_BIT(3) +#define I2C_CMD_INTR_STEERING PPC_BITMASK(6, 7) /* P9 */ +#define I2C_CMD_INTR_STEER_HOST 1 +#define I2C_CMD_INTR_STEER_OCC 2 +#define I2C_CMD_DEV_ADDR PPC_BITMASK(8, 14) +#define I2C_CMD_READ_NOT_WRITE PPC_BIT(15) +#define I2C_CMD_LEN_BYTES PPC_BITMASK(16, 31) +#define I2C_MAX_TFR_LEN 0xfff0ull + +/* I2C mode register */ +#define I2C_MODE_REG 0x6 +#define I2C_MODE_BIT_RATE_DIV PPC_BITMASK(0, 15) +#define I2C_MODE_PORT_NUM PPC_BITMASK(16, 21) +#define I2C_MODE_ENHANCED PPC_BIT(28) +#define I2C_MODE_DIAGNOSTIC PPC_BIT(29) +#define I2C_MODE_PACING_ALLOW PPC_BIT(30) +#define I2C_MODE_WRAP PPC_BIT(31) + +/* I2C watermark register */ +#define I2C_WATERMARK_REG 0x7 +#define I2C_WATERMARK_HIGH PPC_BITMASK(16, 19) +#define I2C_WATERMARK_LOW PPC_BITMASK(24, 27) + +/* + * I2C interrupt mask and condition registers + * + * NB: The function of 0x9 and 0xa changes depending on whether you're rea= ding + * or writing to them. When read they return the interrupt condition b= its + * and on writes they update the interrupt mask register. + * + * The bit definitions are the same for all the interrupt registers. + */ +#define I2C_INTR_MASK_REG 0x8 + +#define I2C_INTR_RAW_COND_REG 0x9 /* read */ +#define I2C_INTR_MASK_OR_REG 0x9 /* write*/ + +#define I2C_INTR_COND_REG 0xa /* read */ +#define I2C_INTR_MASK_AND_REG 0xa /* write */ + +#define I2C_INTR_ALL PPC_BITMASK(16, 31) +#define I2C_INTR_INVALID_CMD PPC_BIT(16) +#define I2C_INTR_LBUS_PARITY_ERR PPC_BIT(17) +#define I2C_INTR_BKEND_OVERRUN_ERR PPC_BIT(18) +#define I2C_INTR_BKEND_ACCESS_ERR PPC_BIT(19) +#define I2C_INTR_ARBT_LOST_ERR PPC_BIT(20) +#define I2C_INTR_NACK_RCVD_ERR PPC_BIT(21) +#define I2C_INTR_DATA_REQ PPC_BIT(22) +#define I2C_INTR_CMD_COMP PPC_BIT(23) +#define I2C_INTR_STOP_ERR PPC_BIT(24) +#define I2C_INTR_I2C_BUSY PPC_BIT(25) +#define I2C_INTR_NOT_I2C_BUSY PPC_BIT(26) +#define I2C_INTR_SCL_EQ_1 PPC_BIT(28) +#define I2C_INTR_SCL_EQ_0 PPC_BIT(29) +#define I2C_INTR_SDA_EQ_1 PPC_BIT(30) +#define I2C_INTR_SDA_EQ_0 PPC_BIT(31) + +/* I2C status register */ +#define I2C_RESET_I2C_REG 0xb /* write */ +#define I2C_RESET_ERRORS 0xc +#define I2C_STAT_REG 0xb /* read */ +#define I2C_STAT_INVALID_CMD PPC_BIT(0) +#define I2C_STAT_LBUS_PARITY_ERR PPC_BIT(1) +#define I2C_STAT_BKEND_OVERRUN_ERR PPC_BIT(2) +#define I2C_STAT_BKEND_ACCESS_ERR PPC_BIT(3) +#define I2C_STAT_ARBT_LOST_ERR PPC_BIT(4) +#define I2C_STAT_NACK_RCVD_ERR PPC_BIT(5) +#define I2C_STAT_DATA_REQ PPC_BIT(6) +#define I2C_STAT_CMD_COMP PPC_BIT(7) +#define I2C_STAT_STOP_ERR PPC_BIT(8) +#define I2C_STAT_UPPER_THRS PPC_BITMASK(9, 15) +#define I2C_STAT_ANY_I2C_INTR PPC_BIT(16) +#define I2C_STAT_PORT_HISTORY_BUSY PPC_BIT(19) +#define I2C_STAT_SCL_INPUT_LEVEL PPC_BIT(20) +#define I2C_STAT_SDA_INPUT_LEVEL PPC_BIT(21) +#define I2C_STAT_PORT_BUSY PPC_BIT(22) +#define I2C_STAT_INTERFACE_BUSY PPC_BIT(23) +#define I2C_STAT_FIFO_ENTRY_COUNT PPC_BITMASK(24, 31) + +#define I2C_STAT_ANY_ERR (I2C_STAT_INVALID_CMD | I2C_STAT_LBUS_PARITY_ERR = | \ + I2C_STAT_BKEND_OVERRUN_ERR | \ + I2C_STAT_BKEND_ACCESS_ERR | I2C_STAT_ARBT_LOST_E= RR | \ + I2C_STAT_NACK_RCVD_ERR | I2C_STAT_STOP_ERR) + + +#define I2C_INTR_ACTIVE \ + ((I2C_STAT_ANY_ERR >> 16) | I2C_INTR_CMD_COMP | I2C_INTR_DATA_REQ) + +/* Pseudo-status used for timeouts */ +#define I2C_STAT_PSEUDO_TIMEOUT PPC_BIT(63) + +/* I2C extended status register */ +#define I2C_EXTD_STAT_REG 0xc +#define I2C_EXTD_STAT_FIFO_SIZE PPC_BITMASK(0, 7) +#define I2C_EXTD_STAT_MSM_CURSTATE PPC_BITMASK(11, 15) +#define I2C_EXTD_STAT_SCL_IN_SYNC PPC_BIT(16) +#define I2C_EXTD_STAT_SDA_IN_SYNC PPC_BIT(17) +#define I2C_EXTD_STAT_S_SCL PPC_BIT(18) +#define I2C_EXTD_STAT_S_SDA PPC_BIT(19) +#define I2C_EXTD_STAT_M_SCL PPC_BIT(20) +#define I2C_EXTD_STAT_M_SDA PPC_BIT(21) +#define I2C_EXTD_STAT_HIGH_WATER PPC_BIT(22) +#define I2C_EXTD_STAT_LOW_WATER PPC_BIT(23) +#define I2C_EXTD_STAT_I2C_BUSY PPC_BIT(24) +#define I2C_EXTD_STAT_SELF_BUSY PPC_BIT(25) +#define I2C_EXTD_STAT_I2C_VERSION PPC_BITMASK(27, 31) + +/* I2C residual front end/back end length */ +#define I2C_RESIDUAL_LEN_REG 0xd +#define I2C_RESIDUAL_FRONT_END PPC_BITMASK(0, 15) +#define I2C_RESIDUAL_BACK_END PPC_BITMASK(16, 31) + +/* Port busy register */ +#define I2C_PORT_BUSY_REG 0xe +#define I2C_SET_S_SCL_REG 0xd +#define I2C_RESET_S_SCL_REG 0xf +#define I2C_SET_S_SDA_REG 0x10 +#define I2C_RESET_S_SDA_REG 0x11 + +#define PNV_I2C_FIFO_SIZE 8 + +#define SMT 4 /* some tests will break if less than 4 = */ + +typedef enum PnvChipType { + PNV_CHIP_POWER8E, /* AKA Murano (default) */ + PNV_CHIP_POWER8, /* AKA Venice */ + PNV_CHIP_POWER8NVL, /* AKA Naples */ + PNV_CHIP_POWER9, /* AKA Nimbus */ + PNV_CHIP_POWER10, +} PnvChipType; + +typedef struct PnvChip { + PnvChipType chip_type; + const char *cpu_model; + uint64_t xscom_base; + uint64_t cfam_id; + uint32_t first_core; + uint32_t num_i2c; +} PnvChip; + +static const PnvChip pnv_chips[] =3D { + { + .chip_type =3D PNV_CHIP_POWER9, + .cpu_model =3D "POWER9", + .xscom_base =3D 0x000603fc00000000ull, + .cfam_id =3D 0x220d104900008000ull, + .first_core =3D 0x0, + .num_i2c =3D 4, + }, + { + .chip_type =3D PNV_CHIP_POWER10, + .cpu_model =3D "POWER10", + .xscom_base =3D 0x000603fc00000000ull, + .cfam_id =3D 0x120da04900008000ull, + .first_core =3D 0x0, + .num_i2c =3D 4, + }, +}; + + +typedef struct { + QTestState *qts; + int engine; + int port; + uint8_t addr; +} pnv_i2c_dev_t; + + +static uint64_t pnv_xscom_addr(uint32_t pcba) +{ + return P10_XSCOM_BASE | ((uint64_t) pcba << 3); +} + +static uint64_t pnv_i2c_xscom_addr(int engine, uint32_t reg) +{ + return pnv_xscom_addr(PNV10_XSCOM_I2CM_BASE + + (PNV10_XSCOM_I2CM_SIZE * engine) + reg); +} + +static uint64_t pnv_i2c_xscom_read(QTestState *qts, int engine, uint32_t r= eg) +{ + return qtest_readq(qts, pnv_i2c_xscom_addr(engine, reg)); +} + +static void pnv_i2c_xscom_write(QTestState *qts, int engine, uint32_t reg, + uint64_t val) +{ + qtest_writeq(qts, pnv_i2c_xscom_addr(engine, reg), val); +} + +/* Write len bytes from buf to i2c device with given addr and port */ +static void pnv_i2c_send(pnv_i2c_dev_t *dev, const uint8_t *buf, uint16_t = len) +{ + int byte_num; + uint64_t reg64; + + /* select requested port */ + reg64 =3D SETFIELD(I2C_MODE_BIT_RATE_DIV, 0ull, 0x2be); + reg64 =3D SETFIELD(I2C_MODE_PORT_NUM, reg64, dev->port); + pnv_i2c_xscom_write(dev->qts, dev->engine, I2C_MODE_REG, reg64); + + /* check status for cmd complete and bus idle */ + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_EXTD_STAT_REG); + g_assert_cmphex(reg64 & I2C_EXTD_STAT_I2C_BUSY, =3D=3D, 0); + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_STAT_REG); + g_assert_cmphex(reg64 & (I2C_STAT_ANY_ERR | I2C_STAT_CMD_COMP), =3D=3D, + I2C_STAT_CMD_COMP); + + /* Send start, with stop, with address and len bytes of data */ + reg64 =3D I2C_CMD_WITH_START | I2C_CMD_WITH_ADDR | I2C_CMD_WITH_STOP; + reg64 =3D SETFIELD(I2C_CMD_DEV_ADDR, reg64, dev->addr); + reg64 =3D SETFIELD(I2C_CMD_LEN_BYTES, reg64, len); + pnv_i2c_xscom_write(dev->qts, dev->engine, I2C_CMD_REG, reg64); + + /* check status for errors */ + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_STAT_REG); + g_assert_cmphex(reg64 & I2C_STAT_ANY_ERR, =3D=3D, 0); + + /* write data bytes to fifo register */ + for (byte_num =3D 0; byte_num < len; byte_num++) { + reg64 =3D SETFIELD(I2C_FIFO, 0ull, buf[byte_num]); + pnv_i2c_xscom_write(dev->qts, dev->engine, I2C_FIFO_REG, reg64); + } + + /* check status for cmd complete and bus idle */ + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_EXTD_STAT_REG); + g_assert_cmphex(reg64 & I2C_EXTD_STAT_I2C_BUSY, =3D=3D, 0); + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_STAT_REG); + g_assert_cmphex(reg64 & (I2C_STAT_ANY_ERR | I2C_STAT_CMD_COMP), =3D=3D, + I2C_STAT_CMD_COMP); +} + +/* Recieve len bytes into buf from i2c device with given addr and port */ +static void pnv_i2c_recv(pnv_i2c_dev_t *dev, uint8_t *buf, uint16_t len) +{ + int byte_num; + uint64_t reg64; + + /* select requested port */ + reg64 =3D SETFIELD(I2C_MODE_BIT_RATE_DIV, 0ull, 0x2be); + reg64 =3D SETFIELD(I2C_MODE_PORT_NUM, reg64, dev->port); + pnv_i2c_xscom_write(dev->qts, dev->engine, I2C_MODE_REG, reg64); + + /* check status for cmd complete and bus idle */ + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_EXTD_STAT_REG); + g_assert_cmphex(reg64 & I2C_EXTD_STAT_I2C_BUSY, =3D=3D, 0); + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_STAT_REG); + g_assert_cmphex(reg64 & (I2C_STAT_ANY_ERR | I2C_STAT_CMD_COMP), =3D=3D, + I2C_STAT_CMD_COMP); + + /* Send start, with stop, with address and len bytes of data */ + reg64 =3D I2C_CMD_WITH_START | I2C_CMD_WITH_ADDR | + I2C_CMD_WITH_STOP | I2C_CMD_READ_NOT_WRITE; + reg64 =3D SETFIELD(I2C_CMD_DEV_ADDR, reg64, dev->addr); + reg64 =3D SETFIELD(I2C_CMD_LEN_BYTES, reg64, len); + pnv_i2c_xscom_write(dev->qts, dev->engine, I2C_CMD_REG, reg64); + + /* check status for errors */ + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_STAT_REG); + g_assert_cmphex(reg64 & I2C_STAT_ANY_ERR, =3D=3D, 0); + + /* Read data bytes from fifo register */ + for (byte_num =3D 0; byte_num < len; byte_num++) { + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_FIFO_REG); + buf[byte_num] =3D GETFIELD(I2C_FIFO, reg64); + } + + /* check status for cmd complete and bus idle */ + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_EXTD_STAT_REG); + g_assert_cmphex(reg64 & I2C_EXTD_STAT_I2C_BUSY, =3D=3D, 0); + reg64 =3D pnv_i2c_xscom_read(dev->qts, dev->engine, I2C_STAT_REG); + g_assert_cmphex(reg64 & (I2C_STAT_ANY_ERR | I2C_STAT_CMD_COMP), =3D=3D, + I2C_STAT_CMD_COMP); +} + +static void pnv_i2c_pca9554_default_cfg(pnv_i2c_dev_t *dev) +{ + uint8_t buf[2]; + + /* input register bits are not inverted */ + buf[0] =3D PCA9554_POLARITY; + buf[1] =3D 0; + pnv_i2c_send(dev, buf, 2); + + /* All pins are inputs */ + buf[0] =3D PCA9554_CONFIG; + buf[1] =3D 0xff; + pnv_i2c_send(dev, buf, 2); + + /* Output value for when pins are outputs */ + buf[0] =3D PCA9554_OUTPUT; + buf[1] =3D 0xff; + pnv_i2c_send(dev, buf, 2); +} + +static void pnv_i2c_pca9554_set_pin(pnv_i2c_dev_t *dev, int pin, bool high) +{ + uint8_t send_buf[2]; + uint8_t recv_buf[2]; + uint8_t mask =3D 0x1 << pin; + uint8_t new_value =3D ((high) ? 1 : 0) << pin; + + /* read current OUTPUT value */ + send_buf[0] =3D PCA9554_OUTPUT; + pnv_i2c_send(dev, send_buf, 1); + pnv_i2c_recv(dev, recv_buf, 1); + + /* write new OUTPUT value */ + send_buf[1] =3D (recv_buf[0] & ~mask) | new_value; + pnv_i2c_send(dev, send_buf, 2); + + /* Update config bit for output */ + send_buf[0] =3D PCA9554_CONFIG; + pnv_i2c_send(dev, send_buf, 1); + pnv_i2c_recv(dev, recv_buf, 1); + send_buf[1] =3D recv_buf[0] & ~mask; + pnv_i2c_send(dev, send_buf, 2); +} + +static uint8_t pnv_i2c_pca9554_read_pins(pnv_i2c_dev_t *dev) +{ + uint8_t send_buf[1]; + uint8_t recv_buf[1]; + uint8_t inputs; + send_buf[0] =3D PCA9554_INPUT; + pnv_i2c_send(dev, send_buf, 1); + pnv_i2c_recv(dev, recv_buf, 1); + inputs =3D recv_buf[0]; + return inputs; +} + +static void pnv_i2c_pca9554_flip_polarity(pnv_i2c_dev_t *dev) +{ + uint8_t recv_buf[1]; + uint8_t send_buf[2]; + + send_buf[0] =3D PCA9554_POLARITY; + pnv_i2c_send(dev, send_buf, 1); + pnv_i2c_recv(dev, recv_buf, 1); + send_buf[1] =3D recv_buf[0] ^ 0xff; + pnv_i2c_send(dev, send_buf, 2); +} + +static void pnv_i2c_pca9554_default_inputs(pnv_i2c_dev_t *dev) +{ + uint8_t pin_values =3D pnv_i2c_pca9554_read_pins(dev); + g_assert_cmphex(pin_values, =3D=3D, 0xff); +} + +/* Check that setting pin values and polarity changes inputs as expected */ +static void pnv_i2c_pca554_set_pins(pnv_i2c_dev_t *dev) +{ + uint8_t pin_values; + pnv_i2c_pca9554_set_pin(dev, 0, 0); + pin_values =3D pnv_i2c_pca9554_read_pins(dev); + g_assert_cmphex(pin_values, =3D=3D, 0xfe); + pnv_i2c_pca9554_flip_polarity(dev); + pin_values =3D pnv_i2c_pca9554_read_pins(dev); + g_assert_cmphex(pin_values, =3D=3D, 0x01); + pnv_i2c_pca9554_set_pin(dev, 2, 0); + pin_values =3D pnv_i2c_pca9554_read_pins(dev); + g_assert_cmphex(pin_values, =3D=3D, 0x05); + pnv_i2c_pca9554_flip_polarity(dev); + pin_values =3D pnv_i2c_pca9554_read_pins(dev); + g_assert_cmphex(pin_values, =3D=3D, 0xfa); + pnv_i2c_pca9554_default_cfg(dev); + pin_values =3D pnv_i2c_pca9554_read_pins(dev); + g_assert_cmphex(pin_values, =3D=3D, 0xff); +} + +static void pnv_i2c_pca9552_default_cfg(pnv_i2c_dev_t *dev) +{ + uint8_t buf[2]; + /* configure pwm/psc regs */ + buf[0] =3D PCA9552_PSC0; + buf[1] =3D 0xff; + pnv_i2c_send(dev, buf, 2); + buf[0] =3D PCA9552_PWM0; + buf[1] =3D 0x80; + pnv_i2c_send(dev, buf, 2); + buf[0] =3D PCA9552_PSC1; + buf[1] =3D 0xff; + pnv_i2c_send(dev, buf, 2); + buf[0] =3D PCA9552_PWM1; + buf[1] =3D 0x80; + pnv_i2c_send(dev, buf, 2); + + /* configure all pins as inputs */ + buf[0] =3D PCA9552_LS0; + buf[1] =3D 0x55; + pnv_i2c_send(dev, buf, 2); + buf[0] =3D PCA9552_LS1; + buf[1] =3D 0x55; + pnv_i2c_send(dev, buf, 2); + buf[0] =3D PCA9552_LS2; + buf[1] =3D 0x55; + pnv_i2c_send(dev, buf, 2); + buf[0] =3D PCA9552_LS3; + buf[1] =3D 0x55; + pnv_i2c_send(dev, buf, 2); +} + +static void pnv_i2c_pca9552_set_pin(pnv_i2c_dev_t *dev, int pin, bool high) +{ + uint8_t send_buf[2]; + uint8_t recv_buf[2]; + uint8_t reg =3D PCA9552_LS0 + (pin / 4); + uint8_t shift =3D (pin % 4) * 2; + uint8_t mask =3D ~(0x3 << shift); + uint8_t new_value =3D ((high) ? 1 : 0) << shift; + + /* read current LSx value */ + send_buf[0] =3D reg; + pnv_i2c_send(dev, send_buf, 1); + pnv_i2c_recv(dev, recv_buf, 1); + + /* write new value to LSx */ + send_buf[1] =3D (recv_buf[0] & mask) | new_value; + pnv_i2c_send(dev, send_buf, 2); +} + +static uint16_t pnv_i2c_pca9552_read_pins(pnv_i2c_dev_t *dev) +{ + uint8_t send_buf[2]; + uint8_t recv_buf[2]; + uint16_t inputs; + send_buf[0] =3D PCA9552_INPUT0; + pnv_i2c_send(dev, send_buf, 1); + pnv_i2c_recv(dev, recv_buf, 1); + inputs =3D recv_buf[0]; + send_buf[0] =3D PCA9552_INPUT1; + pnv_i2c_send(dev, send_buf, 1); + pnv_i2c_recv(dev, recv_buf, 1); + inputs |=3D recv_buf[0] << 8; + return inputs; +} + +static void pnv_i2c_pca9552_default_inputs(pnv_i2c_dev_t *dev) +{ + uint16_t pin_values =3D pnv_i2c_pca9552_read_pins(dev); + g_assert_cmphex(pin_values, =3D=3D, 0xffff); +} + +/* + * Set pins 0-4 one at a time and verify that pins 5-9 are + * set to the same value + */ +static void pnv_i2c_pca552_set_pins(pnv_i2c_dev_t *dev) +{ + uint16_t pin_values; + + /* set pin 0 low */ + pnv_i2c_pca9552_set_pin(dev, 0, 0); + pin_values =3D pnv_i2c_pca9552_read_pins(dev); + + /* pins 0 and 5 should be low */ + g_assert_cmphex(pin_values, =3D=3D, 0xffde); + + /* set pin 1 low */ + pnv_i2c_pca9552_set_pin(dev, 1, 0); + pin_values =3D pnv_i2c_pca9552_read_pins(dev); + + /* pins 0, 1, 5 and 6 should be low */ + g_assert_cmphex(pin_values, =3D=3D, 0xff9c); + + /* set pin 2 low */ + pnv_i2c_pca9552_set_pin(dev, 2, 0); + pin_values =3D pnv_i2c_pca9552_read_pins(dev); + + /* pins 0, 1, 2, 5, 6 and 7 should be low */ + g_assert_cmphex(pin_values, =3D=3D, 0xff18); + + /* set pin 3 low */ + pnv_i2c_pca9552_set_pin(dev, 3, 0); + pin_values =3D pnv_i2c_pca9552_read_pins(dev); + + /* pins 0, 1, 2, 3, 5, 6, 7 and 8 should be low */ + g_assert_cmphex(pin_values, =3D=3D, 0xfe10); + + /* set pin 4 low */ + pnv_i2c_pca9552_set_pin(dev, 4, 0); + pin_values =3D pnv_i2c_pca9552_read_pins(dev); + + /* pins 0, 1, 2, 3, 5, 6, 7, 8 and 9 should be low */ + g_assert_cmphex(pin_values, =3D=3D, 0xfc00); + + /* reset all pins to the high state */ + pnv_i2c_pca9552_default_cfg(dev); + pin_values =3D pnv_i2c_pca9552_read_pins(dev); + + /* verify all pins went back to the high state */ + g_assert_cmphex(pin_values, =3D=3D, 0xffff); +} + +static void reset_engine(QTestState *qts, int engine) +{ + pnv_i2c_xscom_write(qts, engine, I2C_RESET_I2C_REG, 0); +} + +static void check_i2cm_por_regs(QTestState *qts, const PnvChip *chip) +{ + int engine; + for (engine =3D 0; engine < chip->num_i2c; engine++) { + + /* Check version in Extended Status Register */ + uint64_t value =3D pnv_i2c_xscom_read(qts, engine, I2C_EXTD_STAT_R= EG); + g_assert_cmphex(value & I2C_EXTD_STAT_I2C_VERSION, =3D=3D, 0x17000= 00000); + + /* Check for command complete and bus idle in Status Register */ + value =3D pnv_i2c_xscom_read(qts, engine, I2C_STAT_REG); + g_assert_cmphex(value & (I2C_STAT_ANY_ERR | I2C_STAT_CMD_COMP), + =3D=3D, + I2C_STAT_CMD_COMP); + } +} + +static void reset_all(QTestState *qts, const PnvChip *chip) +{ + int engine; + for (engine =3D 0; engine < chip->num_i2c; engine++) { + reset_engine(qts, engine); + pnv_i2c_xscom_write(qts, engine, I2C_MODE_REG, 0x02be040000000000); + } +} + +static void test_host_i2c(const void *data) +{ + const PnvChip *chip =3D data; + QTestState *qts; + const char *machine =3D "powernv8"; + pnv_i2c_dev_t pca9552; + pnv_i2c_dev_t pca9554; + + if (chip->chip_type =3D=3D PNV_CHIP_POWER9) { + machine =3D "powernv9"; + } else if (chip->chip_type =3D=3D PNV_CHIP_POWER10) { + machine =3D "powernv10-rainier"; + } + + qts =3D qtest_initf("-M %s -smp %d,cores=3D1,threads=3D%d -nographic " + "-nodefaults -serial mon:stdio -S " + "-d guest_errors", + machine, SMT, SMT); + + /* Check the I2C master status registers after POR */ + check_i2cm_por_regs(qts, chip); + + /* Now do a forced "immediate" reset on all engines */ + reset_all(qts, chip); + + /* Check that the status values are still good */ + check_i2cm_por_regs(qts, chip); + + /* P9 doesn't have any i2c devices attached at this time */ + if (chip->chip_type !=3D PNV_CHIP_POWER10) { + qtest_quit(qts); + return; + } + + /* Initialize for a P10 pca9552 hotplug device */ + pca9552.qts =3D qts; + pca9552.engine =3D 2; + pca9552.port =3D 1; + pca9552.addr =3D 0x63; + + /* Set all pca9552 pins as inputs */ + pnv_i2c_pca9552_default_cfg(&pca9552); + + /* Check that all pins of the pca9552 are high */ + pnv_i2c_pca9552_default_inputs(&pca9552); + + /* perform individual pin tests */ + pnv_i2c_pca552_set_pins(&pca9552); + + /* Initialize for a P10 pca9554 CableCard Presence detection device */ + pca9554.qts =3D qts; + pca9554.engine =3D 2; + pca9554.port =3D 1; + pca9554.addr =3D 0x25; + + /* Set all pca9554 pins as inputs */ + pnv_i2c_pca9554_default_cfg(&pca9554); + + /* Check that all pins of the pca9554 are high */ + pnv_i2c_pca9554_default_inputs(&pca9554); + + /* perform individual pin tests */ + pnv_i2c_pca554_set_pins(&pca9554); + + qtest_quit(qts); +} + +static void add_test(const char *name, void (*test)(const void *data)) +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(pnv_chips); i++) { + char *tname =3D g_strdup_printf("pnv-xscom/%s/%s", name, + pnv_chips[i].cpu_model); + qtest_add_data_func(tname, &pnv_chips[i], test); + g_free(tname); + } +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + add_test("host-i2c", test_host_i2c); + return g_test_run(); +} --=20 2.31.1