From nobody Tue Feb 10 06:26:51 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1591706729; cv=none; d=zohomail.com; s=zohoarc; b=a/H6ZikQQrCiteNUUMqRIv7qV7VinTPkoOIGLhaREOMHJ8o5aK/4qSEGkie9Q8aklup3yKx+EJZcDEuYXu3smzcJ0WRMZHP1z+4cAuSi0hMxZW75gLsoSWKqEifePaUQpEIxN610iClArSD38S/DEOp2+nbR+3mXpXKCEVFT1zI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591706729; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l+sqnGxutMS7S4hG3iKjsUBAXpEh0W5dJMui9M/7l+Q=; b=kXv7nux19SysaFf+XVEK+sJfOTFaY8siiPtBsUiHYUlYj/lvtDBSwv07JnEgeTn9qvXUNhoQxqKjLzLut7zGXB8tAl0qrl4Q4WEOtJ4mP/WA+lCu1ZnsvIxwFAEjPjUMd96cY90r7qX09uDPRdsw++0svkEZoSMTm0/x6Ul2YiY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591706729102273.29950649413684; Tue, 9 Jun 2020 05:45:29 -0700 (PDT) Received: from localhost ([::1]:40456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jidd7-0007BX-P8 for importer@patchew.org; Tue, 09 Jun 2020 08:45:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jidSp-0000M5-KE; Tue, 09 Jun 2020 08:34:47 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:39003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jidSe-00074i-Hm; Tue, 09 Jun 2020 08:34:43 -0400 Received: by mail-wr1-x441.google.com with SMTP id t18so21115874wru.6; Tue, 09 Jun 2020 05:34:31 -0700 (PDT) Received: from localhost.localdomain (181.red-88-10-103.dynamicip.rima-tde.net. [88.10.103.181]) by smtp.gmail.com with ESMTPSA id c81sm2920931wmd.42.2020.06.09.05.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 05:34:29 -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=l+sqnGxutMS7S4hG3iKjsUBAXpEh0W5dJMui9M/7l+Q=; b=rNR3ApgveJWwvJDFhJ1IHBCPvRP2djQPNMMu/l2o5r+IK8aaHIOdsyVqZONAuAVG5n SSGV+hE3uNMDibES9uA7pDUmFkIQ3UYoA/4VyhHkCFoW/GnQ93fYz93FyIti9fcC6HtS OnuR2+f9+egw1CEK3SOwH9ftG6XhyWnbj3KfZVOlVjQdxyeUDhUbWrLnXTcf8IU55pSQ wsnvB0Iv3IChPzicuT8AJTmeW8IDi3kBXCS5lBiwVX0UBcSTaEFMBNxSMJp7oYwPoRb3 im/ibldYmAcg0K9qcwnkOQifHbVNNyZI13vvbV72JFYc2u6qv8mjS16Oy7saA9q2u4yt nI8Q== 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=l+sqnGxutMS7S4hG3iKjsUBAXpEh0W5dJMui9M/7l+Q=; b=fFkz4bdkNy25QLojLZUbgm8EYLpHQfivQjdK5ymUMRjkVOY8JbmejJYNnBXjcqHSwx +CtsI9qzMJXTcpxIFURXCta3KBIdzcSkFDRJ8z4c/jkqQEpPu9ZL647ZZKC5NJUUsOG/ 9sHtDRSryh/mtNXYYOKIZfBGKZh0F+5agRZ/zDZNqT7n/ZLeOfbcN7aKdmKTnW8xU0r7 HZOEZTq9PAkMpcozEYuajJmdC9iUmkjtcOTWHEXvYyW3JZuV2qK8CETnles5kQgRzGIf 4e/IIXuqCoDo6o3NKze8klgDNnMUZUr9k7tHBhSqXrSZNfcDkxKFixrNTIIYgdMjOOYU Ec/A== X-Gm-Message-State: AOAM532P3K4cIRHihJYTy5klrO1Lpku+5xrD8X1Ze92VRxXono0dfV7X 6MBG9+1FEoJJIfIP0vnJm0h7512h X-Google-Smtp-Source: ABdhPJxIkIw5hvZ5XCCJBD6CQvXERDw2Jdb6ATD6aCR/4WE7i65U1P0Uf2uRRIFXV3w1wsjCgdlCDg== X-Received: by 2002:adf:e887:: with SMTP id d7mr4148418wrm.62.1591706070498; Tue, 09 Jun 2020 05:34:30 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 3/5] hw/misc/led: Add create_led_by_gpio_id() helper Date: Tue, 9 Jun 2020 14:34:23 +0200 Message-Id: <20200609123425.6921-4-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200609123425.6921-1-f4bug@amsat.org> References: <20200609123425.6921-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=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 , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Joaquin de Andres , Michael Roth , Markus Armbruster , qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add create_led_by_gpio_id() to easily connect a LED to a GPIO output. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/misc/led.h | 14 ++++++++++++++ hw/misc/led.c | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/hw/misc/led.h b/include/hw/misc/led.h index 427ca1418e..58393c16de 100644 --- a/include/hw/misc/led.h +++ b/include/hw/misc/led.h @@ -27,4 +27,18 @@ typedef struct LEDState { uint8_t reset_state; /* TODO [GPIO_ACTIVE_LOW, GPIO_ACTIVE_HIGH] */ } LEDState; =20 +/** + * create_led_by_gpio_id: create and LED device + * @parent: the parent object + * @gpio_dev: device exporting GPIOs + * @gpio_id: GPIO ID of this LED + * @name: name of the LED + * + * This utility function creates a LED and connects it to a + * GPIO exported by another device. + */ +DeviceState *create_led_by_gpio_id(Object *parentobj, + DeviceState *gpio_dev, unsigned gpio_id, + const char *led_name); + #endif /* HW_MISC_LED_H */ diff --git a/hw/misc/led.c b/hw/misc/led.c index 233843f581..27882e2f9d 100644 --- a/hw/misc/led.c +++ b/hw/misc/led.c @@ -86,3 +86,23 @@ static void led_register_types(void) } =20 type_init(led_register_types) + +DeviceState *create_led_by_gpio_id(Object *parentobj, + DeviceState *gpio_dev, unsigned gpio_id, + const char *led_name) +{ + DeviceState *dev; + char *name; + + dev =3D qdev_create(NULL, TYPE_LED); + /* TODO set "reset_state" */ + qdev_prop_set_string(dev, "name", led_name); + name =3D g_ascii_strdown(led_name, -1); + name =3D g_strdelimit(name, " #", '-'); + object_property_add_child(parentobj, name, OBJECT(dev)); + g_free(name); + qdev_init_nofail(dev); + qdev_connect_gpio_out(gpio_dev, gpio_id, qdev_get_gpio_in(dev, 0)); + + return dev; +} --=20 2.21.3