From patchwork Fri Jun 19 14:50:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0C0EC433E1 for ; Fri, 19 Jun 2020 14:53:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 70DB0218AC for ; Fri, 19 Jun 2020 14:53:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nbDkTw0d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 70DB0218AC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmIOI-0007am-OD for qemu-devel@archiver.kernel.org; Fri, 19 Jun 2020 10:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmIMJ-00043S-SR; Fri, 19 Jun 2020 10:51:15 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:41930) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jmIMF-0003fq-Tt; Fri, 19 Jun 2020 10:51:11 -0400 Received: by mail-wr1-x444.google.com with SMTP id q2so7532637wrv.8; Fri, 19 Jun 2020 07:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=16xjyyRgElKBAJMa5MhJMGbj3Pu1zRssl4AgrYkonAg=; b=nbDkTw0dLgrqDBjj5Hs5NojrXscADRtzLI9DnFW346lJEOEHt+OFMp/+J7f71V20YR J7BpUYu3IUMeEjUo3cZVj065beiZNzERDr0xw4MqIFWA2gaNWuHBF50JMVeuVfEZq05v YCZ5SmnbnPftLg6M4ZRbISq88hDlVp6tyieb3weMuc+hvzl4GDcs0PJdW1bi6BwyhrWB uneeeH96RZMONxGfsa+V1J8+k+xiHBgbe2ORgtCfJ+RvgwrgNwlz7hfk9Y8mPdCEdKyZ vNGg5VGHU2Iw9EhHTus8IuouHTDIiGnqaMlWhXeCjnglw4bo6QcZZOrPqSMBlazSngpn fIRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=16xjyyRgElKBAJMa5MhJMGbj3Pu1zRssl4AgrYkonAg=; b=Orzbwz55ldmm9aS9HmfdMniNnWzDJMuO41UT1gRcaF6GErA9DUmOH9GHk0jau3JxaX pNJeFg0qnoHw7lBeReadCZUZnBbZitFJnO5OggWE5XpuB6A4BSC/MVBOzbORaL4QFQxj zjBOPSfo7PSCtG3P46juTO2y5K+XrzeabzKq2xjPg3FUD/CiwMI6ArM4UoQ36Bn5JOSF zBFxr7MvGIdwfGJMn6uw626wx1NUQnG0Fp2Ru03kTOwontzexZ9vhew8nFsi9QMtxP/Z +nZGw8C5fLsQDDHlq7/Q7JzzQ0KZX3rZMexfyqxrwQodQIjxUtW1/uyhSAMR9v6H2nyL bmgg== X-Gm-Message-State: AOAM5324o1BVbFq2HmRWRScGfFA2m4RzVEffvQqnf5m7KzHPwmTgdxAe L0xi9muFxQ2AqMwiX8/DaiUWDH0e X-Google-Smtp-Source: ABdhPJzKjaTGJLmvt62Eeo0OJ76G4Al1la6iiWcC2tw4tNJNcaOonTWvdcONcK2nEsSQGhO4d3wbCg== X-Received: by 2002:adf:ee41:: with SMTP id w1mr4647811wro.172.1592578265166; Fri, 19 Jun 2020 07:51:05 -0700 (PDT) Received: from localhost.localdomain (93.red-83-59-160.dynamicip.rima-tde.net. [83.59.160.93]) by smtp.gmail.com with ESMTPSA id e12sm7512548wro.52.2020.06.19.07.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 07:51:04 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 1/4] hw/misc/pca9552: Replace magic value by PCA9552_LED_COUNT definition Date: Fri, 19 Jun 2020 16:50:58 +0200 Message-Id: <20200619145101.1637-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200619145101.1637-1-f4bug@amsat.org> References: <20200619145101.1637-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jeffery , Joaquin de Andres , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Esteban Bosse , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replace the '16' magic value by the PCA9552_LED_COUNT definition. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/misc/pca9552.h | 1 + hw/misc/pca9552.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/hw/misc/pca9552.h b/include/hw/misc/pca9552.h index ebb43c63fe..b2b9a5d9d4 100644 --- a/include/hw/misc/pca9552.h +++ b/include/hw/misc/pca9552.h @@ -15,6 +15,7 @@ #define PCA9552(obj) OBJECT_CHECK(PCA9552State, (obj), TYPE_PCA9552) #define PCA9552_NR_REGS 10 +#define PCA9552_LED_COUNT 16 typedef struct PCA9552State { /*< private >*/ diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index cac729e35a..e015ef0e5d 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -291,7 +291,7 @@ static void pca9552_initfn(Object *obj) * PCA955X device */ s->max_reg = PCA9552_LS3; - s->nr_leds = 16; + s->nr_leds = PCA9552_LED_COUNT; for (led = 0; led < s->nr_leds; led++) { char *name; From patchwork Fri Jun 19 14:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAF23C433E1 for ; Fri, 19 Jun 2020 14:52:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76493217D8 for ; Fri, 19 Jun 2020 14:52:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pmAI8Co2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76493217D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmINa-00068C-Ou for qemu-devel@archiver.kernel.org; Fri, 19 Jun 2020 10:52:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmIMO-000445-7y; Fri, 19 Jun 2020 10:51:16 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46243) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jmIMG-0003g0-Gc; Fri, 19 Jun 2020 10:51:12 -0400 Received: by mail-wr1-x442.google.com with SMTP id x6so9934445wrm.13; Fri, 19 Jun 2020 07:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wgoNLzG3Ol7QUrQ8g37Gepx90Z5CEvbQwQpJANTL2T8=; b=pmAI8Co2QxWxmKECSS9W26vsaeTcf+n55WABZ4+RWvJz2xnYuoep2Bk/9e3Y6baP86 8KyeqcHsQM1/zoLo0dQO8GlB2z9CtVv04nSj2dIFzO1JxGPEpfcIRFAXija9iad2Pkjn kVSo/rCDig+jT0K1jHzY+sLvJ07QAKp+bXfYes+hKNsREmIjqAN01VmdKC19UkSNodsa Z/O8Dq4q9C+646o3SKDV2c1pm34SuKwK2b0VS6ImcioDtZ9McvMwQEOv9NJ+YxO6dWWO 9eYAreeWE91FrdZcCsrQHAElSif/q+RqyD9hSzjRZEohc4fmVR5NlcejulIUpwRMPOcC Icaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wgoNLzG3Ol7QUrQ8g37Gepx90Z5CEvbQwQpJANTL2T8=; b=S11Dhsgcd4c3nPpC1rwUSSvYwtxEG/JivU/2rq9KuDoqRBVaHfKEYQsn/habAHNTF3 Z9odM91zrIhLnkMEZlxrHTDqYq8ZKFaFm5zcYyH4NErwQYb2QhNI3jXWSG2PL16t/cnz 8LbuLhRFd0Yf3fgZy9ltwXwCKj8qJRzrnVNF3k5Hv+o/58wXzvalZkb5BYsnzF/rl1dc SFLsLjThZBb6IVDAma2jBO0WzsKwZ1WJzI2YMYLM41ITAqG8AK/20bV4MtTFlSDamSAd r0Wu6hvyDO4WQT2TSd64ySALnZLNi6om7Jm1n5wQ0KA0AIwVTQcQYAvDji82wfl9txh+ hbqA== X-Gm-Message-State: AOAM530DKmOz5DSCeLHBYtM6cypSJjRMtJm7lsAQ+vLjTDtvtBp9JiLH T2tMwI9hH/FmHmGvVDu8xsPnzprf X-Google-Smtp-Source: ABdhPJxyV344rnv7Lr69+btk2PUIWQDs0WssAlM/yxiHfCRigKvK8sQhNu0Dk/aoMuuQ1vfSofbtXQ== X-Received: by 2002:adf:e587:: with SMTP id l7mr4556399wrm.352.1592578266239; Fri, 19 Jun 2020 07:51:06 -0700 (PDT) Received: from localhost.localdomain (93.red-83-59-160.dynamicip.rima-tde.net. [83.59.160.93]) by smtp.gmail.com with ESMTPSA id e12sm7512548wro.52.2020.06.19.07.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 07:51:05 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 2/4] hw/misc/pca9552: Add a PCA955X_LED_MAX definition Date: Fri, 19 Jun 2020 16:50:59 +0200 Message-Id: <20200619145101.1637-3-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200619145101.1637-1-f4bug@amsat.org> References: <20200619145101.1637-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jeffery , Joaquin de Andres , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Esteban Bosse , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The current code models the PCA9552, but there are comments saying the code could be easily adapted for the rest of the PCA955x family. Since we assume we have at most 16 LEDs (for the PCA9552), add a definition and check the instance doesn't use more than this number. This makes the code a bit safer in case other PCA955x devices are added. Signed-off-by: Philippe Mathieu-Daudé --- hw/misc/pca9552.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index e015ef0e5d..00fa91b7f4 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -18,6 +18,8 @@ #include "qapi/error.h" #include "qapi/visitor.h" +#define PCA955X_LED_MAX 16 + #define PCA9552_LED_ON 0x0 #define PCA9552_LED_OFF 0x1 #define PCA9552_LED_PWM0 0x2 @@ -303,6 +305,17 @@ static void pca9552_initfn(Object *obj) } } +static void pca9552_realize(DeviceState *dev, Error **errp) +{ + PCA9552State *s = PCA9552(dev); + + if (s->nr_leds > PCA955X_LED_MAX) { + error_setg(errp, "%s invalid led count %u (max: %u)", + __func__, s->nr_leds, PCA955X_LED_MAX); + return; + } +} + static void pca9552_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -311,6 +324,7 @@ static void pca9552_class_init(ObjectClass *klass, void *data) k->event = pca9552_event; k->recv = pca9552_recv; k->send = pca9552_send; + dc->realize = pca9552_realize; dc->reset = pca9552_reset; dc->vmsd = &pca9552_vmstate; } From patchwork Fri Jun 19 14:51:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.7 required=3.0 tests=DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C2CDC433DF for ; Fri, 19 Jun 2020 14:54:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC47E217D8 for ; Fri, 19 Jun 2020 14:54:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uoRbwSZm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC47E217D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmIP4-0000e4-1E for qemu-devel@archiver.kernel.org; Fri, 19 Jun 2020 10:54:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmIMO-00044A-8i; Fri, 19 Jun 2020 10:51:16 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:42029) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jmIMH-0003gI-AI; Fri, 19 Jun 2020 10:51:12 -0400 Received: by mail-wr1-x443.google.com with SMTP id o11so2256400wrv.9; Fri, 19 Jun 2020 07:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TQIXtSJLI5JjENe67Ipi+8d5uXeAJhyCfAa9D+kxU/g=; b=uoRbwSZm+L9xhgmRaY2MHMY4Qm4lK5ZKhzayABUp2IlkIplF0P2+9sBQJ9Lc0brvEO smeAqqdOT1D/GBUcIyx/mDNYE73QX6+RtBM5e0rH7MOyKShCOHVqSSddApteHhoC5giP 3N6nQfMqtri74mOOhxsGcRzmwn7xhJJe22mUh3x/W6CEhMKqfzVpanrFrM4B1SAD+A1c GgPoRIwK4iFVyjzzf894nf5qerCntU1sYo7wTpHD4waSf0jIKN679Yem4lo35WNngg2+ 7ENpvzizhjW51hBdWV3ImLvNQ/G7YwtkKQK4R07PeP19/s0UMOCwq77JXmcmhREuy+S/ tPnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TQIXtSJLI5JjENe67Ipi+8d5uXeAJhyCfAa9D+kxU/g=; b=TF7itPwW+ClRznICMMT1SszculRfsbGu6l75gOOC3GnqFthrtBO6EK4LaXr1Zct4M6 MyaDsY3/Cb5DiHLJxEDeGl6cf1Qn9fgsFBfsJ4anTSuUvafCDfb6qj8JQiXp+dsp1Lze bC5SYMCvlH1PgrTZ4bN+A1G/eXJ+soqa4+d/pmDC9W1YdI9LrtDRx6Gi6VXGf+aZYQTJ k4jK1e2WJ+lUcTammG1UmtrwPk825NIsD2yKV1jhWcG+WaoghV72J+vIee+WT1d8ljbw /LWoJz/yVmOXd5Nep0lDYlyKN0FhK47KEfLZxU+KbEg3awfFgfpT/JG5KPWxApI4vZaV SacA== X-Gm-Message-State: AOAM533XXar3T4TtuEgPJeLAQ4HI9pOw1+MR09XbG07UEeJnoLGhROqw WFdb5x0aYiZasQurTo6WO60043Sz X-Google-Smtp-Source: ABdhPJxcC57NgYaJSnls9KxA8eFSXqY93ruQtXaaa9HkahBjbJHasGM6jQ4y7kO+CcYr+HPeSZJleA== X-Received: by 2002:adf:f512:: with SMTP id q18mr4869863wro.38.1592578267419; Fri, 19 Jun 2020 07:51:07 -0700 (PDT) Received: from localhost.localdomain (93.red-83-59-160.dynamicip.rima-tde.net. [83.59.160.93]) by smtp.gmail.com with ESMTPSA id e12sm7512548wro.52.2020.06.19.07.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 07:51:06 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 3/4] hw/misc/pca9552: Trace LED On/Off events Date: Fri, 19 Jun 2020 16:51:00 +0200 Message-Id: <20200619145101.1637-4-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200619145101.1637-1-f4bug@amsat.org> References: <20200619145101.1637-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jeffery , Joaquin de Andres , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Esteban Bosse , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add a trivial representation of the PCA9552 LEDs. Example booting obmc-phosphor-image: $ qemu-system-arm -M witherspoon-bmc -trace pca9552_leds_status 19286@1592574170.202791:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [*...............] 19286@1592574170.203609:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [**..............] 19286@1592574170.204102:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [***.............] 19286@1592574170.204415:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****............] 19286@1592574170.204758:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*..] 19286@1592574170.205070:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........**.] 19286@1592574170.205380:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***] 19286@1592574235.384845:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*] 19286@1592574235.894049:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***] 19286@1592574236.404277:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*] 19286@1592574236.914644:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***] 19286@1592574237.424558:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*] 19286@1592574237.934580:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***] 19286@1592574238.444688:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*] We notice the LED #14 (front-power LED) starts to blink. This LED is described in the witherspoon device-tree [*]: front-power { retain-state-shutdown; default-state = "keep"; gpios = <&pca0 14 GPIO_ACTIVE_LOW>; }; [*] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts?id=b1f9be9392f0#n140 Suggested-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- include/hw/misc/pca9552.h | 1 + hw/misc/pca9552.c | 29 +++++++++++++++++++++++++++++ hw/misc/trace-events | 3 +++ 3 files changed, 33 insertions(+) diff --git a/include/hw/misc/pca9552.h b/include/hw/misc/pca9552.h index b2b9a5d9d4..4e171d88c6 100644 --- a/include/hw/misc/pca9552.h +++ b/include/hw/misc/pca9552.h @@ -26,6 +26,7 @@ typedef struct PCA9552State { uint8_t pointer; uint8_t regs[PCA9552_NR_REGS]; + uint16_t leds_status; /* Holds latest INPUT0 & INPUT1 status */ uint8_t max_reg; uint8_t nr_leds; } PCA9552State; diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index 00fa91b7f4..50c149077d 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -12,11 +12,13 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/module.h" +#include "qemu/bitops.h" #include "hw/misc/pca9552.h" #include "hw/misc/pca9552_regs.h" #include "migration/vmstate.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "trace.h" #define PCA955X_LED_MAX 16 @@ -60,6 +62,32 @@ static void pca9552_update_pin_input(PCA9552State *s) } } +static void pca9552_display_leds(PCA9552State *s) +{ + uint16_t leds_status, led_changed; + int i; + + leds_status = (s->regs[PCA9552_INPUT1] << 8) | s->regs[PCA9552_INPUT0]; + led_changed = s->leds_status ^ leds_status; + if (!led_changed) { + return; + } + s->leds_status = leds_status; + if (trace_event_get_state_backends(TRACE_PCA9552_LEDS_STATUS)) { + char buf[PCA9552_LED_COUNT + 1]; + + for (i = 0; i < s->nr_leds; i++) { + if (extract32(leds_status, i, 1)) { + buf[i] = '*'; + } else { + buf[i] = '.'; + } + } + buf[i] = '\0'; + trace_pca9552_leds_status(s, buf); + } +} + static uint8_t pca9552_read(PCA9552State *s, uint8_t reg) { switch (reg) { @@ -97,6 +125,7 @@ static void pca9552_write(PCA9552State *s, uint8_t reg, uint8_t data) case PCA9552_LS3: s->regs[reg] = data; pca9552_update_pin_input(s); + pca9552_display_leds(s); break; case PCA9552_INPUT0: diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 5561746866..5d9505ad0f 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -206,3 +206,6 @@ via1_rtc_cmd_pram_sect_write(int sector, int offset, int addr, int value) "secto # grlib_ahb_apb_pnp.c grlib_ahb_pnp_read(uint64_t addr, uint32_t value) "AHB PnP read addr:0x%03"PRIx64" data:0x%08x" grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx64" data:0x%08x" + +# pca9552.c +pca9552_leds_status(void *object, const char *buf) "%p LEDs 0-15 [%s]"