From nobody Thu Nov 14 17:51:53 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1708331865; cv=none; d=zohomail.com; s=zohoarc; b=cjs8I7GRZSTrOvRW+esIJYGtmQBQQuMkkciGk2NveuDCLuVyPcfZLZDgF8SIQ5IDLxm/mu+tRKbyBUjZ86TaabVLgwgC/MMm/SxiBcQHdN2HtpizGKvLsqyrLIeQ6oEVrzDDtpHWzDEBurS/P2e2BQKFitZ0vVl4uQ6+cSHU5Kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708331865; 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=sDOAPyy/p7ldU2KSryWFNhizVqq3Tur5f2N+VyCj+Jk=; b=DKZ11XYqJzmQK6WVcvTkPzxRuCGJGgVtYPTvapJ0FCDK91rnKx1wBTrQDwKEyoXTDhsl1kqMomAIPkKaiCW/Q4yycTZGSGOaOJwtj4GMxxpOy6kdxzFMix0MaXb4O/p8xjjm7Pn7lvGaCjMGdmw3cZSJREWpy+Tgmh6CJ34rvxc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708331865790152.68631607338045; Mon, 19 Feb 2024 00:37:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbz41-0002qp-7q; Mon, 19 Feb 2024 03:31:49 -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 1rbz3z-0002p1-66; Mon, 19 Feb 2024 03:31:47 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbz3x-0002Sl-GC; Mon, 19 Feb 2024 03:31:46 -0500 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6e0a479a6cbso1965146b3a.0; Mon, 19 Feb 2024 00:31:44 -0800 (PST) Received: from wheely.local0.net ([1.146.38.93]) by smtp.gmail.com with ESMTPSA id mo7-20020a1709030a8700b001db5ecd115bsm3838348plb.276.2024.02.19.00.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 00:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708331503; x=1708936303; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sDOAPyy/p7ldU2KSryWFNhizVqq3Tur5f2N+VyCj+Jk=; b=I/nA/IToSiVWixf75+dOf9gtQbQjsOB4WAGuWAbKCokl1aRG2CHQjNUqECUB37Snbs 2c3YIGEauhhpdNaE5Dy9cFWTG+n+RE18wUs5j8Ly4i26rG9OCpXB0KyNA7q/iW+GlmGp Y9YL+zzvoi/ewhFspqSLgJR5OUNjd8882boOVXdv2ILUgS3ZzlvOSVpdlT+gOXrgMovK ddO2DrmSrZj0HRPWM1tquHSuKFMrcFfyIl/EYPH7C8p6TDKNC6OKEjTOdVF3e34bvKA6 PNUVnetQQ+bnnfTb2wENufdJtGvE8gfCw4tGrohp9aaBEOtE7RZBUKDqf43EFyDxQsie mikw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708331503; x=1708936303; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sDOAPyy/p7ldU2KSryWFNhizVqq3Tur5f2N+VyCj+Jk=; b=ZGgIRXn/LO2oJ5i3pTYG87wKgemDoYARcSlimJFWE14WG8X1tI4bAnvZQGL6uDODyt 9xOJ9yFgl3Y1r0Lgi9TSM+mbBaFLBlRPKy13clDfELEbwDg5dCnkdQzbWkz4N3FeK+fk iBoP3gD2Q03vtVUP1s8mqpstjWyoCNOcpaLunmalvgzL9q/bEXfdQw/bsJsFaGH9G9tX MeDzKTbKMDQmF2gvk3sO3hljl2VSb1AxHoBZ4QD6tjZCAdPSUiGTowSRraREYqKhzhxS alPJkokdi+KpPqqQWq1nRQt14lh5+0CkwVe7xzng6wwQ4Eu7yK+rdNwyrRzhIBHsFtOu DUEg== X-Forwarded-Encrypted: i=1; AJvYcCWp4rAWOkojbYIeI4NOFwTfz35iHl2+w77DmqCYC8bL6i5aDfzObaDwi9vaI0Rmn1P+je3R5SOnsXqkv0X2q8Ik9GAZ X-Gm-Message-State: AOJu0YzXkb4b5Rm6K+mqf16t13DTfVjYbs+ZTzJTszqqPUYRWwKvm0sU qMD9nOtaFIMb4FOm8f7g/EN3W4pTg1ARg4EiFowfjv2p7w558nEW+kMgi+P0 X-Google-Smtp-Source: AGHT+IEFSqVxeU7otzcrYd+EsN8sdfE+xDPIubDp2REcfr5M+Ioqj5AUswQ1MT1ceQaovXgMFZvCKA== X-Received: by 2002:a05:6a20:a88f:b0:19e:3cbf:b311 with SMTP id ca15-20020a056a20a88f00b0019e3cbfb311mr7919030pzb.35.1708331503378; Mon, 19 Feb 2024 00:31:43 -0800 (PST) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Daniel Henrique Barboza , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Harsh Prateek Bora , Glenn Miles , Andrew Jeffery Subject: [PULL 23/49] misc/pca9552: Fix inverted input status Date: Mon, 19 Feb 2024 18:29:12 +1000 Message-ID: <20240219082938.238302-24-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240219082938.238302-1-npiggin@gmail.com> References: <20240219082938.238302-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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 @gmail.com) X-ZM-MESSAGEID: 1708331866367100002 Content-Type: text/plain; charset="utf-8" From: Glenn Miles 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 Signed-off-by: Nicholas Piggin --- 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 72b653463f..f00a149d61 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.42.0