get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/1641661/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1641661,
    "url": "http://patchwork.ozlabs.org/api/patches/1641661/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-ide/patch/20220610081801.11854-8-Sergey.Semin@baikalelectronics.ru/",
    "project": {
        "id": 13,
        "url": "http://patchwork.ozlabs.org/api/projects/13/?format=api",
        "name": "Linux IDE development",
        "link_name": "linux-ide",
        "list_id": "linux-ide.vger.kernel.org",
        "list_email": "linux-ide@vger.kernel.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20220610081801.11854-8-Sergey.Semin@baikalelectronics.ru>",
    "list_archive_url": null,
    "date": "2022-06-10T08:17:45",
    "name": "[v4,07/23] ata: libahci_platform: Convert to using devm bulk clocks API",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "9562fc06c00dc8dec9a6d4a03ec0a969438f3e42",
    "submitter": {
        "id": 78624,
        "url": "http://patchwork.ozlabs.org/api/people/78624/?format=api",
        "name": "Serge Semin",
        "email": "Sergey.Semin@baikalelectronics.ru"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/linux-ide/patch/20220610081801.11854-8-Sergey.Semin@baikalelectronics.ru/mbox/",
    "series": [
        {
            "id": 304159,
            "url": "http://patchwork.ozlabs.org/api/series/304159/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-ide/list/?series=304159",
            "date": "2022-06-10T08:17:42",
            "name": "ata: ahci: Add DWC/Baikal-T1 AHCI SATA support",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/304159/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1641661/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1641661/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<linux-ide-owner@vger.kernel.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org",
        "Authentication-Results": [
            "bilbo.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=baikalelectronics.ru header.i=@baikalelectronics.ru\n header.a=rsa-sha256 header.s=mail header.b=TFTkhn0H;\n\tdkim-atps=neutral",
            "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2620:137:e000::1:20; helo=out1.vger.email;\n envelope-from=linux-ide-owner@vger.kernel.org; receiver=<UNKNOWN>)"
        ],
        "Received": [
            "from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20])\n\tby bilbo.ozlabs.org (Postfix) with ESMTP id 4LKDPj2chlz9s5V\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Jun 2022 18:18:49 +1000 (AEST)",
            "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n        id S1347358AbiFJISq (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n        Fri, 10 Jun 2022 04:18:46 -0400",
            "from lindbergh.monkeyblade.net ([23.128.96.19]:35016 \"EHLO\n        lindbergh.monkeyblade.net\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n        with ESMTP id S1347230AbiFJISU (ORCPT\n        <rfc822;linux-ide@vger.kernel.org>); Fri, 10 Jun 2022 04:18:20 -0400",
            "from mail.baikalelectronics.com (mail.baikalelectronics.com\n [87.245.175.230])\n        by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0E0F9237942;\n        Fri, 10 Jun 2022 01:18:17 -0700 (PDT)",
            "from mail (mail.baikal.int [192.168.51.25])\n        by mail.baikalelectronics.com (Postfix) with ESMTP id 0FAA616A8;\n        Fri, 10 Jun 2022 11:19:01 +0300 (MSK)",
            "from localhost (192.168.53.207) by mail (192.168.51.25) with\n Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 10 Jun 2022 11:18:08 +0300"
        ],
        "DKIM-Filter": "OpenDKIM Filter v2.11.0 mail.baikalelectronics.com 0FAA616A8",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=baikalelectronics.ru; s=mail; t=1654849141;\n        bh=MsGCYuH4hth07vE45hdKdzDWXH/lqfjSFMGO2xICtoI=;\n        h=From:To:CC:Subject:Date:In-Reply-To:References:From;\n        b=TFTkhn0HavJgAQq8nuZo9ORtrSyTKy3tgfOHoDL0zkZCFQKKcrxXsTHC0fa82XrD7\n         Zmial6Oq34Lhc/pWkiNcxysTouZ4A4RVosXBBi0jR/TJ9h6XHhtPlAAVAGSt5gPp0z\n         x+/ld6eGZ8rZZbrC9Gk6FQCA144ZXau3lr/vhlAI=",
        "From": "Serge Semin <Sergey.Semin@baikalelectronics.ru>",
        "To": "Damien Le Moal <damien.lemoal@opensource.wdc.com>,\n        Hans de Goede <hdegoede@redhat.com>,\n        Jens Axboe <axboe@kernel.dk>, Hannes Reinecke <hare@suse.de>",
        "CC": "Serge Semin <Sergey.Semin@baikalelectronics.ru>,\n        Serge Semin <fancer.lancer@gmail.com>,\n        Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>,\n        Pavel Parkhomenko <Pavel.Parkhomenko@baikalelectronics.ru>,\n        Rob Herring <robh+dt@kernel.org>, <linux-ide@vger.kernel.org>,\n        <linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>",
        "Subject": "[PATCH v4 07/23] ata: libahci_platform: Convert to using devm bulk\n clocks API",
        "Date": "Fri, 10 Jun 2022 11:17:45 +0300",
        "Message-ID": "<20220610081801.11854-8-Sergey.Semin@baikalelectronics.ru>",
        "In-Reply-To": "<20220610081801.11854-1-Sergey.Semin@baikalelectronics.ru>",
        "References": "<20220610081801.11854-1-Sergey.Semin@baikalelectronics.ru>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain",
        "X-ClientProxiedBy": "MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25)",
        "X-Spam-Status": "No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n        DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS,\n        T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no\n        version=3.4.6",
        "X-Spam-Checker-Version": "SpamAssassin 3.4.6 (2021-04-09) on\n        lindbergh.monkeyblade.net",
        "Precedence": "bulk",
        "List-ID": "<linux-ide.vger.kernel.org>",
        "X-Mailing-List": "linux-ide@vger.kernel.org"
    },
    "content": "In order to simplify the clock-related code there is a way to convert the\ncurrent fixed clocks array into using the common bulk clocks kernel API\nwith dynamic set of the clock handlers and device-managed clock-resource\ntracking. It's a bit tricky due to the complication coming from the\nrequirement to support the platforms (da850, spear13xx) with the\nnon-OF-based clock source, but still doable.\n\nBefore this modification there are two methods have been used to get the\nclocks connected to an AHCI device: clk_get() - to get the very first\nclock in the list and of_clk_get() - to get the rest of them. Basically\nthe platforms with non-OF-based clocks definition could specify only a\nsingle reference clock source. The platforms with OF-hw clocks have been\nluckier and could setup up to AHCI_MAX_CLKS clocks. Such semantic can be\nretained with using devm_clk_bulk_get_all() to retrieve the clocks defined\nvia the DT firmware and devm_clk_get_optional() otherwise. In both cases\nusing the device-managed version of the methods will cause the automatic\nresources deallocation on the AHCI device removal event. The only\ncomplicated part in the suggested approach is the explicit allocation and\ninitialization of the clk_bulk_data structure instance for the non-OF\nreference clocks. It's required in order to use the Bulk Clocks API for\nthe both denoted cases of the clocks definition.\n\nNote aside with the clock-related code reduction and natural\nsimplification, there are several bonuses the suggested modification\nprovides. First of all the limitation of having no greater than\nAHCI_MAX_CLKS clocks is now removed, since the devm_clk_bulk_get_all()\nmethod will allocate as many reference clocks data descriptors as there\nare clocks specified for the device. Secondly the clock names are\nauto-detected. So the LLDD (glue) drivers can make sure that the required\nclocks are specified just by checking the clock IDs in the clk_bulk_data\narray.  Thirdly using the handy Bulk Clocks kernel API improves the\nclocks-handling code readability. And the last but not least this\nmodification implements a true optional clocks support to the\nahci_platform_get_resources() method. Indeed the previous clocks getting\nprocedure just stopped getting the clocks on any errors (aside from\nnon-critical -EPROBE_DEFER) in a way so the callee wasn't even informed\nabout abnormal loop termination. The new implementation lacks of such\nproblem. The ahci_platform_get_resources() will return an error code if\nthe corresponding clocks getting method ends execution abnormally.\n\nSigned-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>\nReviewed-by: Hannes Reinecke <hare@suse.de>\n\n---\n\nChangelog v2:\n- Convert to checking the error-case first in the devm_clk_bulk_get_all()\n  method invocation. (@Damien)\n- Fix some grammar mistakes in the comments.\n---\n drivers/ata/ahci.h             |  4 +-\n drivers/ata/libahci_platform.c | 84 ++++++++++++++++------------------\n 2 files changed, 41 insertions(+), 47 deletions(-)",
    "diff": "diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h\nindex ad11a4c52fbe..c3770a19781b 100644\n--- a/drivers/ata/ahci.h\n+++ b/drivers/ata/ahci.h\n@@ -38,7 +38,6 @@\n \n enum {\n \tAHCI_MAX_PORTS\t\t= 32,\n-\tAHCI_MAX_CLKS\t\t= 5,\n \tAHCI_MAX_SG\t\t= 168, /* hardware max is 64K */\n \tAHCI_DMA_BOUNDARY\t= 0xffffffff,\n \tAHCI_MAX_CMDS\t\t= 32,\n@@ -339,7 +338,8 @@ struct ahci_host_priv {\n \tu32\t\t\tem_msg_type;\t/* EM message type */\n \tu32\t\t\tremapped_nvme;\t/* NVMe remapped device count */\n \tbool\t\t\tgot_runtime_pm; /* Did we do pm_runtime_get? */\n-\tstruct clk\t\t*clks[AHCI_MAX_CLKS]; /* Optional */\n+\tunsigned int\t\tn_clks;\n+\tstruct clk_bulk_data\t*clks;\t\t/* Optional */\n \tstruct reset_control\t*rsts;\t\t/* Optional */\n \tstruct regulator\t**target_pwrs;\t/* Optional */\n \tstruct regulator\t*ahci_regulator;/* Optional */\ndiff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c\nindex 1e9e825d6cc5..814804582d1d 100644\n--- a/drivers/ata/libahci_platform.c\n+++ b/drivers/ata/libahci_platform.c\n@@ -8,6 +8,7 @@\n  *   Anton Vorontsov <avorontsov@ru.mvista.com>\n  */\n \n+#include <linux/clk-provider.h>\n #include <linux/clk.h>\n #include <linux/kernel.h>\n #include <linux/gfp.h>\n@@ -97,28 +98,14 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_phys);\n  * ahci_platform_enable_clks - Enable platform clocks\n  * @hpriv: host private area to store config values\n  *\n- * This function enables all the clks found in hpriv->clks, starting at\n- * index 0. If any clk fails to enable it disables all the clks already\n- * enabled in reverse order, and then returns an error.\n+ * This function enables all the clks found for the AHCI device.\n  *\n  * RETURNS:\n  * 0 on success otherwise a negative error code\n  */\n int ahci_platform_enable_clks(struct ahci_host_priv *hpriv)\n {\n-\tint c, rc;\n-\n-\tfor (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) {\n-\t\trc = clk_prepare_enable(hpriv->clks[c]);\n-\t\tif (rc)\n-\t\t\tgoto disable_unprepare_clk;\n-\t}\n-\treturn 0;\n-\n-disable_unprepare_clk:\n-\twhile (--c >= 0)\n-\t\tclk_disable_unprepare(hpriv->clks[c]);\n-\treturn rc;\n+\treturn clk_bulk_prepare_enable(hpriv->n_clks, hpriv->clks);\n }\n EXPORT_SYMBOL_GPL(ahci_platform_enable_clks);\n \n@@ -126,16 +113,13 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_clks);\n  * ahci_platform_disable_clks - Disable platform clocks\n  * @hpriv: host private area to store config values\n  *\n- * This function disables all the clks found in hpriv->clks, in reverse\n- * order of ahci_platform_enable_clks (starting at the end of the array).\n+ * This function disables all the clocks enabled before\n+ * (bulk-clocks-disable function is supposed to do that in reverse\n+ * from the enabling procedure order).\n  */\n void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)\n {\n-\tint c;\n-\n-\tfor (c = AHCI_MAX_CLKS - 1; c >= 0; c--)\n-\t\tif (hpriv->clks[c])\n-\t\t\tclk_disable_unprepare(hpriv->clks[c]);\n+\tclk_bulk_disable_unprepare(hpriv->n_clks, hpriv->clks);\n }\n EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);\n \n@@ -292,8 +276,6 @@ static void ahci_platform_put_resources(struct device *dev, void *res)\n \t\tpm_runtime_disable(dev);\n \t}\n \n-\tfor (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++)\n-\t\tclk_put(hpriv->clks[c]);\n \t/*\n \t * The regulators are tied to child node device and not to the\n \t * SATA device itself. So we can't use devm for automatically\n@@ -374,8 +356,8 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,\n  * 1) mmio registers (IORESOURCE_MEM 0, mandatory)\n  * 2) regulator for controlling the targets power (optional)\n  *    regulator for controlling the AHCI controller (optional)\n- * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,\n- *    or for non devicetree enabled platforms a single clock\n+ * 3) all clocks specified in the devicetree node, or a single\n+ *    clock for non-OF platforms (optional)\n  * 4) resets, if flags has AHCI_PLATFORM_GET_RESETS (optional)\n  * 5) phys (optional)\n  *\n@@ -385,11 +367,10 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,\n struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,\n \t\t\t\t\t\t   unsigned int flags)\n {\n+\tint child_nodes, rc = -ENOMEM, enabled_ports = 0;\n \tstruct device *dev = &pdev->dev;\n \tstruct ahci_host_priv *hpriv;\n-\tstruct clk *clk;\n \tstruct device_node *child;\n-\tint i, enabled_ports = 0, rc = -ENOMEM, child_nodes;\n \tu32 mask_port_map = 0;\n \n \tif (!devres_open_group(dev, NULL, GFP_KERNEL))\n@@ -415,25 +396,38 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,\n \t\tgoto err_out;\n \t}\n \n-\tfor (i = 0; i < AHCI_MAX_CLKS; i++) {\n+\t/*\n+\t * Bulk clocks getting procedure can fail to find any clock due to\n+\t * running on a non-OF platform or due to the clocks being defined in\n+\t * bypass of the DT firmware (like da850, spear13xx). In that case we\n+\t * fallback to getting a single clock source right from the dev clocks\n+\t * list.\n+\t */\n+\trc = devm_clk_bulk_get_all(dev, &hpriv->clks);\n+\tif (rc < 0)\n+\t\tgoto err_out;\n+\n+\tif (rc > 0) {\n+\t\t/* Got clocks in bulk */\n+\t\thpriv->n_clks = rc;\n+\t} else {\n \t\t/*\n-\t\t * For now we must use clk_get(dev, NULL) for the first clock,\n-\t\t * because some platforms (da850, spear13xx) are not yet\n-\t\t * converted to use devicetree for clocks.  For new platforms\n-\t\t * this is equivalent to of_clk_get(dev->of_node, 0).\n+\t\t * No clock bulk found: fallback to manually getting\n+\t\t * the optional clock.\n \t\t */\n-\t\tif (i == 0)\n-\t\t\tclk = clk_get(dev, NULL);\n-\t\telse\n-\t\t\tclk = of_clk_get(dev->of_node, i);\n-\n-\t\tif (IS_ERR(clk)) {\n-\t\t\trc = PTR_ERR(clk);\n-\t\t\tif (rc == -EPROBE_DEFER)\n-\t\t\t\tgoto err_out;\n-\t\t\tbreak;\n+\t\thpriv->clks = devm_kzalloc(dev, sizeof(*hpriv->clks), GFP_KERNEL);\n+\t\tif (!hpriv->clks) {\n+\t\t\trc = -ENOMEM;\n+\t\t\tgoto err_out;\n+\t\t}\n+\t\thpriv->clks->clk = devm_clk_get_optional(dev, NULL);\n+\t\tif (IS_ERR(hpriv->clks->clk)) {\n+\t\t\trc = PTR_ERR(hpriv->clks->clk);\n+\t\t\tgoto err_out;\n+\t\t} else if (hpriv->clks->clk) {\n+\t\t\thpriv->clks->id = __clk_get_name(hpriv->clks->clk);\n+\t\t\thpriv->n_clks = 1;\n \t\t}\n-\t\thpriv->clks[i] = clk;\n \t}\n \n \thpriv->ahci_regulator = devm_regulator_get(dev, \"ahci\");\n",
    "prefixes": [
        "v4",
        "07/23"
    ]
}