From patchwork Fri Oct 6 21:42:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 149423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp610064vqo; Fri, 6 Oct 2023 14:43:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7cWgkWVQuBAm+wzctJHmgWwMoZbY0B7TexZFYbpG83IxJBlrEjv/b4eZU6ig/fBfQtoKZ X-Received: by 2002:a17:902:6941:b0:1bb:b855:db3c with SMTP id k1-20020a170902694100b001bbb855db3cmr7241529plt.41.1696628594064; Fri, 06 Oct 2023 14:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696628594; cv=none; d=google.com; s=arc-20160816; b=fX9TxTxQLk4VGV6+qMmqTyrVAUrGAKxnIppHskZ7uyETpXvKORArBLQfuPZJlnk/Ye sTk0Q8lc0wiTgKTDD+2QEnWRvea6vxcBVYMw92yC+L1t0E8tODOUCeh88eaemMNe8V46 G7WTlVsVJ+YBPlB2ekzcsDZ8gRcdGJ3ueORWPVYukmjEpxAnMiAkqhtS3K8nWVahoRh2 FLgx15dvcCrQbBYiG9P0Pn93QkOFPYkCT/QrVqqKZQSdUQqu+ZwczSZpdsbj/YzGV9XL E6GbqTPyCpKPLskwO2brc105Un2ZiZaWBatCB2WqMASZyb3YGe6agwyjL7+LX9ZQSN2w VwAA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rP1oFHMvgIuHS3shtAWs+9IFf7pCo7Y5i9ep4rwZeAA=; fh=XfDFbBKkeoSLeGk8ssr9fc7u7Y9Ml0KIdUx0UjwCPJM=; b=Ukh0yWXoNiweI5Yr6u+0pC/16AT4tD5dyIi5GRZXlFs+tmKmdschrq4FDgcXyXqPZs NAxIFOKb3W5glhLvQaz9QPVZE5p1hLcTelvNq2vVgVoK+SUuihVlfygYe95MNK2/QuTR jLWAppFzxevroerydFs/N22vezUfIOIvWjvXrmtl3Zc3tnUXTW3QeinPvEXwN7CcUtjc VdEtWUpH38Bjg8GRziB4i4P7d5AyuZiItqq3IOLEh/4RdNpqLIlAHUI3NYTT6EyOiMBM CzlVrXwbIQMFixQfbfROIBikRBuWtX1kBVGmslyc1w3AOzs9SGo/8LdOvGKFzZvYbFEo Tkhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nm6dsHfp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i8-20020a17090332c800b001c8920e3021si2048004plr.539.2023.10.06.14.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 14:43:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nm6dsHfp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B57C980843E0; Fri, 6 Oct 2023 14:43:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233530AbjJFVms (ORCPT + 18 others); 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 X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 06 Oct 2023 14:43:11 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779044024521143526 X-GMAIL-MSGID: 1779044024521143526 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/xilinx_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 -#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 = { .llseek = noop_llseek, }; -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 = NULL; - int retval = 0; + struct device *dev = &pdev->dev; + int retval; dev_info(dev, "Xilinx icap port driver\n"); @@ -636,72 +631,39 @@ static int hwicap_setup(struct device *dev, int id, devt = MKDEV(XHWICAP_MAJOR, XHWICAP_MINOR + id); - drvdata = kzalloc(sizeof(struct hwicap_drvdata), GFP_KERNEL); + drvdata = devm_kzalloc(dev, sizeof(struct hwicap_drvdata), GFP_KERNEL); if (!drvdata) { retval = -ENOMEM; - goto failed0; + goto failed; } dev_set_drvdata(dev, (void *)drvdata); - if (!regs_res) { - dev_err(dev, "Couldn't get registers resource\n"); - retval = -EFAULT; - goto failed1; - } - - drvdata->mem_start = regs_res->start; - drvdata->mem_end = regs_res->end; - drvdata->mem_size = 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 = -EBUSY; - goto failed1; + drvdata->base_address = devm_platform_ioremap_resource(pdev, 0); + if (!drvdata->base_address) { + retval = -ENODEV; + goto failed; } drvdata->devt = devt; drvdata->dev = dev; - drvdata->base_address = ioremap(drvdata->mem_start, drvdata->mem_size); - if (!drvdata->base_address) { - dev_err(dev, "ioremap() failed\n"); - retval = -ENOMEM; - goto failed2; - } - drvdata->config = config; drvdata->config_regs = config_regs; mutex_init(&drvdata->sem); drvdata->is_open = 0; - 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 = THIS_MODULE; retval = cdev_add(&drvdata->cdev, devt, 1); if (retval) { dev_err(dev, "cdev_add() failed\n"); - goto failed3; + goto failed; } device_create(&icap_class, dev, devt, NULL, "%s%d", DRIVER_NAME, id); return 0; /* success */ - 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] = 0; mutex_unlock(&icap_sem); @@ -723,75 +685,22 @@ static struct hwicap_driver_config fifo_icap_config = { .reset = fifo_icap_reset, }; -#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 = of_address_to_resource(op->dev.of_node, 0, &res); - if (rc) { - dev_err(&op->dev, "invalid address\n"); - return rc; - } - - id = 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 = &v4_config_registers; - family = of_get_property(op->dev.of_node, "xlnx,family", NULL); - - if (family) { - if (!strcmp(family, "virtex2p")) - regs = &v2_config_registers; - else if (!strcmp(family, "virtex4")) - regs = &v4_config_registers; - else if (!strcmp(family, "virtex5")) - regs = &v5_config_registers; - else if (!strcmp(family, "virtex6")) - regs = &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 = -1; - match = of_match_device(hwicap_of_match, &pdev->dev); - if (match) - return hwicap_of_probe(pdev, match->data); + config = device_get_match_data(&pdev->dev); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -ENODEV; + of_property_read_u32(pdev->dev.of_node, "port-number", &id); /* It's most likely that we're using V4, if the family is not * specified */ regs = &v4_config_registers; - family = pdev->dev.platform_data; - - if (family) { + if (!of_property_read_string(pdev->dev.of_node, "xlnx,family", &family)) { if (!strcmp(family, "virtex2p")) regs = &v2_config_registers; else if (!strcmp(family, "virtex4")) @@ -801,9 +710,7 @@ static int hwicap_drv_probe(struct platform_device *pdev) else if (!strcmp(family, "virtex6")) regs = &v6_config_registers; } - - return hwicap_setup(&pdev->dev, pdev->id, res, - &buffer_icap_config, regs); + return hwicap_setup(pdev, id, config, regs); } static void hwicap_drv_remove(struct platform_device *pdev) @@ -815,16 +722,12 @@ static void hwicap_drv_remove(struct platform_device *pdev) 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); mutex_lock(&icap_sem); probed_devices[MINOR(dev->devt)-XHWICAP_MINOR] = 0; mutex_unlock(&icap_sem); } -#ifdef CONFIG_OF /* Match table for device tree binding */ static const struct of_device_id hwicap_of_match[] = { { .compatible = "xlnx,opb-hwicap-1.00.b", .data = &buffer_icap_config}, @@ -832,9 +735,6 @@ static const struct of_device_id hwicap_of_match[] = { {}, }; MODULE_DEVICE_TABLE(of, hwicap_of_match); -#else -#define hwicap_of_match NULL -#endif static struct platform_driver hwicap_platform_driver = { .probe = hwicap_drv_probe,