Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1064164pxu; Mon, 23 Nov 2020 10:40:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIW38NHU3bcnlAsKabFa7Zh928KHfzMXVhm0pmwe5/yszQi+9DBiQ199B9exSHhnkRjmsP X-Received: by 2002:aa7:da44:: with SMTP id w4mr513891eds.131.1606156831825; Mon, 23 Nov 2020 10:40:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606156831; cv=none; d=google.com; s=arc-20160816; b=c7e9vv1Lx55mTGt5RewyNfhOc8ppqqgQxv5MXgcc/q47vkrjt5R6HS2UstO8wyYOVX uAdRqKLOE7kptqRa/BOD5F7/jIe90FiSanTXMYPnhEt7aM4T3CGjyhx/WFdpDAfeY/uk x0YkQk4Lis49GvfQ9sOjeVhaY797YauQlBt8BNN1HwZuswIepqQlA+3UHU0Db8eLkD5T xzx+tbQlCZDNdYAJLmHSFqTwQqqk0FiY0g9TZdaBS097eE7xLgbps2O9naZtiruASoOl +ubLcuofOB8cq3RbEbUjGtstCBvGSej3EQZRhZ19rsqYzb+oS3V4NIglL/SlXi6Yc9Uh NeCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qCZdpsZ9w8Hjo6es8iVhLHL/3qvcyHe4pa7qSYMYVPM=; b=GDdfWVZrDFltXk4l/FgbhFoLofEAL9TiOpg436xn9rkbJnECBS6qkxT3Vk31vB6Laq qwm3BPQS1uD6c0L0/RAlAaOoR0NwtWvC/kGKofUEO0N9m5aSltXk+xtBmyYuIlWea2j0 h+TA8E57/sc+gkloGaDkUc8eq+MFxp0nQuhoUVU4eijzf1jf6snWfG7G13qz+efiTnDl zX2CqKoj3GA03rIMg5QgEyuxedwX6jqX4BUTpTpeCHtorZSOiWkmYFoyVoNZiXJxu2T+ gktxwgdL0okD3VsBKU/IyX9r6mH3S2RfQNesXO5mGzJGx83r1vS7IxyKOeqEIXu7Nc+9 7ugg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f15si7022352edc.153.2020.11.23.10.40.09; Mon, 23 Nov 2020 10:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387625AbgKWSiq (ORCPT + 99 others); Mon, 23 Nov 2020 13:38:46 -0500 Received: from mx2.suse.de ([195.135.220.15]:59350 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgKWSip (ORCPT ); Mon, 23 Nov 2020 13:38:45 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 19EAAACA2; Mon, 23 Nov 2020 18:38:43 +0000 (UTC) From: Nicolas Saenz Julienne To: u.kleine-koenig@pengutronix.de, linux-kernel@vger.kernel.org, Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Nicolas Saenz Julienne Cc: linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, wahrenst@gmx.net, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, p.zabel@pengutronix.de, linux-gpio@vger.kernel.org, linus.walleij@linaro.org, linux-clk@vger.kernel.org, sboyd@kernel.org, linux-rpi-kernel@lists.infradead.org, bgolaszewski@baylibre.com, andy.shevchenko@gmail.com Subject: [PATCH v5 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get() Date: Mon, 23 Nov 2020 19:38:23 +0100 Message-Id: <20201123183833.18750-3-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123183833.18750-1-nsaenzjulienne@suse.de> References: <20201123183833.18750-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It'll simplify the firmware handling for most consumers. Suggested-by: Bartosz Golaszewski Signed-off-by: Nicolas Saenz Julienne --- Changes since v4: - Rearrange function calls for clarity, same functionality Changes since v2: - Create devm_rpi_firmware_get() drivers/firmware/raspberrypi.c | 29 ++++++++++++++++++++++ include/soc/bcm2835/raspberrypi-firmware.h | 8 ++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c index ed793aef7851..e2a5f6f59357 100644 --- a/drivers/firmware/raspberrypi.c +++ b/drivers/firmware/raspberrypi.c @@ -243,6 +243,13 @@ void rpi_firmware_put(struct rpi_firmware *fw) } EXPORT_SYMBOL_GPL(rpi_firmware_put); +static void devm_rpi_firmware_put(void *data) +{ + struct rpi_firmware *fw = data; + + rpi_firmware_put(fw); +} + static int rpi_firmware_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -326,6 +333,28 @@ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node) } EXPORT_SYMBOL_GPL(rpi_firmware_get); +/** + * devm_rpi_firmware_get - Get pointer to rpi_firmware structure. + * @firmware_node: Pointer to the firmware Device Tree node. + * + * Returns NULL is the firmware device is not ready. + */ +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, + struct device_node *firmware_node) +{ + struct rpi_firmware *fw; + + fw = rpi_firmware_get(firmware_node); + if (!fw) + return NULL; + + if (devm_add_action_or_reset(dev, devm_rpi_firmware_put, fw)) + return NULL; + + return fw; +} +EXPORT_SYMBOL_GPL(devm_rpi_firmware_get); + static const struct of_device_id rpi_firmware_of_match[] = { { .compatible = "raspberrypi,bcm2835-firmware", }, {}, diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h index fdfef7fe40df..73ad784fca96 100644 --- a/include/soc/bcm2835/raspberrypi-firmware.h +++ b/include/soc/bcm2835/raspberrypi-firmware.h @@ -142,6 +142,8 @@ int rpi_firmware_property_list(struct rpi_firmware *fw, void *data, size_t tag_size); void rpi_firmware_put(struct rpi_firmware *fw); struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node); +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, + struct device_node *firmware_node); #else static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag, void *data, size_t len) @@ -160,6 +162,12 @@ static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware { return NULL; } + +static inline struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, + struct device_node *firmware_node) +{ + return NULL; +} #endif #endif /* __SOC_RASPBERRY_FIRMWARE_H__ */ -- 2.29.2