From nobody Fri Jan 2 22:22:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AE71E94125 for ; Fri, 6 Oct 2023 21:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233473AbjJFVms (ORCPT ); Fri, 6 Oct 2023 17:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233383AbjJFVmr (ORCPT ); Fri, 6 Oct 2023 17:42:47 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9140BE for ; Fri, 6 Oct 2023 14:42:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C10D5C433C7; Fri, 6 Oct 2023 21:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696628565; bh=pvPNLy/jIeBGg7wC3/rVpwO1svAHAzEF2z2bam7K3tE=; h=From:To:Cc:Subject:Date:From; b=nm6dsHfpevhcfM5r2Uqhi4R+LYo+202uay+6OilP7M+LSSwUo2ManE85lPe7EbN+Z 2pAauATX+saPRunU8STGqsqcNGD21MULlOuN1QxCGM7cJFe4fK5Fgj+7A2bDoQahvl teZwElwYhn3VijjeSsG5XwUqZiiQsLm3P8dSCu4sYhcrkcj9f8iBDxMmkJW2KbCpAC ehuG91uVo1iKy/3GDhYUWeNfQmBr9ZyCuMKEFJBMM58BYIwooXDf68gZy16BaB+xHZ wme7p0q0wXzVNKDG3FExO7IOA9X8hpBMzKTsOmp3Z0R35BCGfuc2zxQGTGpS87v4D3 YM0M8Yeh33QgQ== Received: (nullmailer pid 337386 invoked by uid 1000); Fri, 06 Oct 2023 21:42:43 -0000 From: Rob Herring To: Arnd Bergmann , Greg Kroah-Hartman , Michal Simek Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] char: xilinx_hwicap: Modernize driver probe Date: Fri, 6 Oct 2023 16:42:28 -0500 Message-Id: <20231006214228.337064-1-robh@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rework Xilinx hwicap driver probe to use current best practices using devres APIs, device_get_match_data(), and typed firmware property accessors. There's no longer any non-DT probing, so CONFIG_OF ifdefs can be dropped. Signed-off-by: Rob Herring --- drivers/char/xilinx_hwicap/xilinx_hwicap.c | 138 +++------------------ 1 file changed, 19 insertions(+), 119 deletions(-) diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xili= nx_hwicap/xilinx_hwicap.c index f60bb6151402..019cf6079cec 100644 --- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c +++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c @@ -84,18 +84,13 @@ #include #include #include +#include #include +#include #include #include #include =20 -#ifdef CONFIG_OF -/* For open firmware. */ -#include -#include -#include -#endif - #include "xilinx_hwicap.h" #include "buffer_icap.h" #include "fifo_icap.h" @@ -601,14 +596,14 @@ static const struct file_operations hwicap_fops =3D { .llseek =3D noop_llseek, }; =20 -static int hwicap_setup(struct device *dev, int id, - const struct resource *regs_res, +static int hwicap_setup(struct platform_device *pdev, int id, const struct hwicap_driver_config *config, const struct config_registers *config_regs) { dev_t devt; struct hwicap_drvdata *drvdata =3D NULL; - int retval =3D 0; + struct device *dev =3D &pdev->dev; + int retval; =20 dev_info(dev, "Xilinx icap port driver\n"); =20 @@ -636,72 +631,39 @@ static int hwicap_setup(struct device *dev, int id, =20 devt =3D MKDEV(XHWICAP_MAJOR, XHWICAP_MINOR + id); =20 - drvdata =3D kzalloc(sizeof(struct hwicap_drvdata), GFP_KERNEL); + drvdata =3D devm_kzalloc(dev, sizeof(struct hwicap_drvdata), GFP_KERNEL); if (!drvdata) { retval =3D -ENOMEM; - goto failed0; + goto failed; } dev_set_drvdata(dev, (void *)drvdata); =20 - if (!regs_res) { - dev_err(dev, "Couldn't get registers resource\n"); - retval =3D -EFAULT; - goto failed1; - } - - drvdata->mem_start =3D regs_res->start; - drvdata->mem_end =3D regs_res->end; - drvdata->mem_size =3D resource_size(regs_res); - - if (!request_mem_region(drvdata->mem_start, - drvdata->mem_size, DRIVER_NAME)) { - dev_err(dev, "Couldn't lock memory region at %Lx\n", - (unsigned long long) regs_res->start); - retval =3D -EBUSY; - goto failed1; + drvdata->base_address =3D devm_platform_ioremap_resource(pdev, 0); + if (!drvdata->base_address) { + retval =3D -ENODEV; + goto failed; } =20 drvdata->devt =3D devt; drvdata->dev =3D dev; - drvdata->base_address =3D ioremap(drvdata->mem_start, drvdata->mem_size); - if (!drvdata->base_address) { - dev_err(dev, "ioremap() failed\n"); - retval =3D -ENOMEM; - goto failed2; - } - drvdata->config =3D config; drvdata->config_regs =3D config_regs; =20 mutex_init(&drvdata->sem); drvdata->is_open =3D 0; =20 - dev_info(dev, "ioremap %llx to %p with size %llx\n", - (unsigned long long) drvdata->mem_start, - drvdata->base_address, - (unsigned long long) drvdata->mem_size); - cdev_init(&drvdata->cdev, &hwicap_fops); drvdata->cdev.owner =3D THIS_MODULE; retval =3D cdev_add(&drvdata->cdev, devt, 1); if (retval) { dev_err(dev, "cdev_add() failed\n"); - goto failed3; + goto failed; } =20 device_create(&icap_class, dev, devt, NULL, "%s%d", DRIVER_NAME, id); return 0; /* success */ =20 - failed3: - iounmap(drvdata->base_address); - - failed2: - release_mem_region(regs_res->start, drvdata->mem_size); - - failed1: - kfree(drvdata); - - failed0: + failed: mutex_lock(&icap_sem); probed_devices[id] =3D 0; mutex_unlock(&icap_sem); @@ -723,75 +685,22 @@ static struct hwicap_driver_config fifo_icap_config = =3D { .reset =3D fifo_icap_reset, }; =20 -#ifdef CONFIG_OF -static int hwicap_of_probe(struct platform_device *op, - const struct hwicap_driver_config *config) -{ - struct resource res; - const unsigned int *id; - const char *family; - int rc; - const struct config_registers *regs; - - - rc =3D of_address_to_resource(op->dev.of_node, 0, &res); - if (rc) { - dev_err(&op->dev, "invalid address\n"); - return rc; - } - - id =3D of_get_property(op->dev.of_node, "port-number", NULL); - - /* It's most likely that we're using V4, if the family is not - * specified - */ - regs =3D &v4_config_registers; - family =3D of_get_property(op->dev.of_node, "xlnx,family", NULL); - - if (family) { - if (!strcmp(family, "virtex2p")) - regs =3D &v2_config_registers; - else if (!strcmp(family, "virtex4")) - regs =3D &v4_config_registers; - else if (!strcmp(family, "virtex5")) - regs =3D &v5_config_registers; - else if (!strcmp(family, "virtex6")) - regs =3D &v6_config_registers; - } - return hwicap_setup(&op->dev, id ? *id : -1, &res, config, - regs); -} -#else -static inline int hwicap_of_probe(struct platform_device *op, - const struct hwicap_driver_config *config) -{ - return -EINVAL; -} -#endif /* CONFIG_OF */ - -static const struct of_device_id hwicap_of_match[]; static int hwicap_drv_probe(struct platform_device *pdev) { - const struct of_device_id *match; - struct resource *res; const struct config_registers *regs; + const struct hwicap_driver_config *config; const char *family; + int id =3D -1; =20 - match =3D of_match_device(hwicap_of_match, &pdev->dev); - if (match) - return hwicap_of_probe(pdev, match->data); + config =3D device_get_match_data(&pdev->dev); =20 - res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -ENODEV; + of_property_read_u32(pdev->dev.of_node, "port-number", &id); =20 /* It's most likely that we're using V4, if the family is not * specified */ regs =3D &v4_config_registers; - family =3D pdev->dev.platform_data; - - if (family) { + if (!of_property_read_string(pdev->dev.of_node, "xlnx,family", &family)) { if (!strcmp(family, "virtex2p")) regs =3D &v2_config_registers; else if (!strcmp(family, "virtex4")) @@ -801,9 +710,7 @@ static int hwicap_drv_probe(struct platform_device *pde= v) else if (!strcmp(family, "virtex6")) regs =3D &v6_config_registers; } - - return hwicap_setup(&pdev->dev, pdev->id, res, - &buffer_icap_config, regs); + return hwicap_setup(pdev, id, config, regs); } =20 static void hwicap_drv_remove(struct platform_device *pdev) @@ -815,16 +722,12 @@ static void hwicap_drv_remove(struct platform_device = *pdev) =20 device_destroy(&icap_class, drvdata->devt); cdev_del(&drvdata->cdev); - iounmap(drvdata->base_address); - release_mem_region(drvdata->mem_start, drvdata->mem_size); - kfree(drvdata); =20 mutex_lock(&icap_sem); probed_devices[MINOR(dev->devt)-XHWICAP_MINOR] =3D 0; mutex_unlock(&icap_sem); } =20 -#ifdef CONFIG_OF /* Match table for device tree binding */ static const struct of_device_id hwicap_of_match[] =3D { { .compatible =3D "xlnx,opb-hwicap-1.00.b", .data =3D &buffer_icap_config= }, @@ -832,9 +735,6 @@ static const struct of_device_id hwicap_of_match[] =3D { {}, }; MODULE_DEVICE_TABLE(of, hwicap_of_match); -#else -#define hwicap_of_match NULL -#endif =20 static struct platform_driver hwicap_platform_driver =3D { .probe =3D hwicap_drv_probe, --=20 2.40.1